Changeset 165

Show
Ignore:
Timestamp:
10/07/09 20:34:09 (7 weeks ago)
Author:
hachi
Message:

Add $job->declined and test for external locking.

Location:
trunk
Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/CHANGES

    r141 r165  
     1    - Add $job->declined method for workers to be able to decline handling 
     2      a job at this time. 
     3 
    141.08 () 
    25    - Added $client->grab_and_work_on($handle) to securely work on a job  
  • trunk/MANIFEST

    r145 r165  
    4343t/coalesce.t 
    4444t/dead-dbs.t 
     45t/declined.t 
    4546t/empty-db.t 
    4647t/evenly-distribute.t 
  • trunk/lib/TheSchwartz/Job.pm

    r163 r165  
    162162} 
    163163 
     164sub was_declined { 
     165    my $job = shift; 
     166    if (@_) { 
     167        $job->{__was_declined} = shift; 
     168    } 
     169    return $job->{__was_declined}; 
     170} 
     171 
     172 
    164173sub did_something { 
    165174    my $job = shift; 
     
    194203    } 
    195204    $job->_failed($msg, $ex_status, 0); 
     205} 
     206 
     207sub declined { 
     208    my ($job) = @_; 
     209    if ($job->did_something) { 
     210        $job->debug("can't call 'declined' on already finished job"); 
     211        return 0; 
     212    } 
     213    $job->debug("job declined.  retry will be considered after lease is up at " . $job->grabbed_until); 
     214 
     215    $job->was_declined(1); 
     216 
     217    # we do nothing regarding the job's status 
    196218} 
    197219 
     
    444466or loaded, setting whether it has to C<$value> first, if specified. 
    445467 
     468=head2 C<$job-E<gt>was_declined()> 
     469 
     470Sets (if given an argument) and returns the value of the was_declined flag for 
     471a job object. See also C<$job-E<gt>declined()> 
     472 
    446473=head2 C<$job-E<gt>debug( $msg )> 
    447474 
     
    486513as C<$exit_status> (or C<1>), and the job is removed from the queue. 
    487514 
     515=head2 C<$job-E<gt>declined()> 
     516 
     517Report that the job has been declined for handling at this time, which means that 
     518the job will be retried after the next grabbed_until interval, and does not count 
     519against the max_retries count. 
     520 
    488521=head2 C<$job-E<gt>replace_with( @jobs )> 
    489522 
  • trunk/lib/TheSchwartz/Worker.pm

    r134 r165  
    3030        $res = $class->work($job); 
    3131    }; 
     32    my $errstr = $@; 
    3233 
    3334    my $cjob = $client->current_job; 
    34     if ($@) { 
    35         $job->debug("Eval failure: $@"); 
     35    if ($errstr) { 
     36        $job->debug("Eval failure: $errstr"); 
    3637        $cjob->failed($@); 
    3738    } 
    38     unless ($cjob->did_something) { 
     39    if (! $cjob->was_declined && ! $cjob->did_something) { 
    3940        $cjob->failed('Job did not explicitly complete, fail, or get replaced'); 
    4041    }