Changeset 1406

Show
Ignore:
Timestamp:
02/23/08 01:33:03 (5 months ago)
Author:
bchoate
Message:

Updated with prioritization support from TheSchwartz 1.07

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/release-30/extlib/TheSchwartz.pm

    r1104 r1406  
    33package TheSchwartz; 
    44use strict; 
    5 use fields qw( databases retry_seconds dead_dsns retry_at funcmap_cache verbose all_abilities current_abilities current_job cached_drivers driver_cache_expiration scoreboard ); 
    6  
    7 our $VERSION = "1.06"; 
     5use fields qw( databases retry_seconds dead_dsns retry_at funcmap_cache verbose all_abilities current_abilities current_job cached_drivers driver_cache_expiration scoreboard prioritize ); 
     6 
     7our $VERSION = "1.07"; 
    88 
    99use Carp qw( croak ); 
     
    3636 
    3737    $client->{retry_seconds} = delete $args{retry_seconds} || RETRY_DEFAULT; 
     38    $client->set_prioritize(delete $args{prioritize}); 
    3839    $client->set_verbose(delete $args{verbose}); 
    3940    $client->set_scoreboard(delete $args{scoreboard}); 
     
    167168                funcid        => $funcid, 
    168169                @options 
    169                 }, { limit => $limit }); 
     170                }, { limit => $limit, 
     171                    ( $client->prioritize ? ( sort => 'priority', 
     172                    direction => 'descend' ) : () ) 
     173                }); 
    170174        } else { 
    171175            push @jobs, $driver->search('TheSchwartz::Job' => { 
    172176                funcid        => $funcid, 
    173177                @options 
    174                 }, { limit => $limit }); 
     178                }, { limit => $limit, 
     179                    ( $client->prioritize ? ( sort => 'priority', 
     180                        direction => 'descend' ) : () ) 
     181                } 
     182            ); 
    175183        } 
    176184    } 
     
    215223                    grabbed_until => \ "<= $unixtime", 
    216224                    coalesce      => { op => $op, value => $coval }, 
    217                 }, { limit => $FIND_JOB_BATCH_SIZE }); 
     225                }, { limit => $FIND_JOB_BATCH_SIZE, 
     226                    ( $client->prioritize ? ( sort => 'priority', 
     227                        direction => 'descend' ) : () ) 
     228                } 
     229            ); 
    218230        }; 
    219231        if ($@) { 
     
    254266                    run_after     => \ "<= $unixtime", 
    255267                    grabbed_until => \ "<= $unixtime", 
    256                 }, { limit => $FIND_JOB_BATCH_SIZE }); 
     268                }, { limit => $FIND_JOB_BATCH_SIZE, 
     269                    ( $client->prioritize ? ( sort => 'priority', 
     270                    direction => 'descend' ) : () ) 
     271                } 
     272            ); 
    257273        }; 
    258274        if ($@) { 
     
    504520    my $class = $job ? $job->funcname : undef; 
    505521    if ($job) { 
    506         $job->debug("TheSchwartz::work_once got job of class '$class'"); 
     522        my $priority = $job->priority ? ", priority " . $job->priority : ""; 
     523        $job->debug("TheSchwartz::work_once got job of class '$class'$priority"); 
    507524    } else { 
    508525        $client->debug("TheSchwartz::work_once found no jobs"); 
     
    682699} 
    683700 
     701sub prioritize { 
     702    my TheSchwartz $client = shift; 
     703    return $client->{prioritize}; 
     704} 
     705 
     706sub set_prioritize { 
     707    my TheSchwartz $client = shift; 
     708    $client->{prioritize} = shift; 
     709} 
     710 
    684711# current job being worked.  so if something dies, work_safely knows which to mark as dead. 
    685712sub current_job { 
     
    806833messages will not be logged. 
    807834 
     835=item * C<prioritize> 
     836 
     837A value indicating whether to utilize the job 'priority' field when selecting 
     838jobs to be processed. If unspecified, jobs will always be executed in a 
     839randomized order. 
     840 
    808841=item * C<driver_cache_expiration> 
    809842 
  • branches/release-30/extlib/TheSchwartz/FuncMap.pm

    r1098 r1406  
    1717    my($driver, $funcname) = @_; 
    1818 
     19    ## Attempt to select funcmap record by name. If successful, return 
     20    ## object, otherwise proceed with insertion and return. 
     21    my ($map) = $driver->search('TheSchwartz::FuncMap' => 
     22            { funcname => $funcname } 
     23        ); 
     24    return $map if $map; 
     25 
    1926    ## Attempt to insert a new funcmap row. Since the funcname column is 
    2027    ## UNIQUE, if the row already exists, an exception will be thrown. 
    21     my $map = $class->new; 
     28    $map = $class->new; 
    2229    $map->funcname($funcname); 
    2330    eval { $driver->insert($map) };