Skip to content

Commit

Permalink
Ensure the job was grabbed by other workers more paranoiac.
Browse files Browse the repository at this point in the history
Data::ObjectDriver doesn't ensure the object's value is in bounds of
original search query, beacuse to give a chance to pick the data from
cache layer. So we need to be more paranoic to make sure it's
not grabbed by other workers when to grab a job.
  • Loading branch information
aklaswad committed Mar 12, 2015
1 parent c2fe54b commit 453b0b7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/TheSchwartz.pm
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,16 @@ JOB:
$server_time + ( $worker_class->grab_for || 1 ) );

## Update the job in the database, and end the transaction.
if ( $driver->update( $job, { grabbed_until => $old_grabbed_until } )
< 1 )
## NOTE: For some reason, D::OD doesn't ensure the object's value is
## in bounds of original search query. so we need to be more paranoic
## to make sure it's not grabbed by other workers.
my $unixtime = $driver->dbd->sql_for_unixtime;
if ( $driver->update( $job, {
grabbed_until => [
'-and',
{ op => '=', value => $old_grabbed_until},
\" <= $unixtime"
]}) < 1 )
{
## We lost the race to get this particular job--another worker must
## have got it and already updated it. Move on to the next job.
Expand Down

0 comments on commit 453b0b7

Please sign in to comment.