Permalink
Browse files

can set priority by failed job.

  • Loading branch information...
1 parent 7899641 commit 3615d42c1e620073368f33863e86371c7792570a @nekokak committed Feb 8, 2011
Showing with 23 additions and 2 deletions.
  1. +5 −2 lib/Jonk.pm
  2. +18 −0 t/job.t
View
@@ -48,7 +48,7 @@ sub new {
delete_query => sprintf('DELETE FROM %s WHERE id = ?', $table_name),
- failed_query => sprintf('UPDATE %s SET retry_cnt = retry_cnt + 1, run_after = ?, grabbed_until = 0 WHERE id = ?', $table_name),
+ failed_query => sprintf('UPDATE %s SET retry_cnt = retry_cnt + 1, run_after = ?, grabbed_until = 0, priority = ? WHERE id = ?', $table_name),
unixtime_query => _settled_unixtime_query($driver),
@@ -228,12 +228,15 @@ sub _failed {
my ($self, $job_id, $opt) = @_;
my $retry_delay = $self->_server_unixitime + (defined($opt->{retry_delay}) ? $opt->{retry_delay} : 60);
+ my $priority = (defined($opt->{priority}) ? $opt->{priority} : 0);
+
try {
my $sth = $self->{dbh}->prepare_cached($self->{failed_query});
- $sth->execute($retry_delay, $job_id);
+ $sth->execute($retry_delay, $priority, $job_id);
$sth->finish;
return $sth->rows;
} catch {
+ warn 'ababaaaba';
$self->{_errstr} = "can't update job from job queue database: $_";
return;
};
View
18 t/job.t
@@ -84,6 +84,24 @@ subtest 'failed job' => sub {
$sth->execute($job_id);
ok not $sth->fetchrow_hashref;
}
+
+ subtest 'failed and set priority' => sub {
+ my $job_id = $client->insert('MyWorker', 'arg');
+ ok $job_id;
+
+ my $job = $client->lookup_job($job_id);
+ is $job->priority, 0;
+ $job->failed({retry_delay => 0});
+
+ $job = $client->lookup_job($job_id);
+ is $job->priority, 0;
+ $job->failed({retry_delay => 0, priority => 1});
+
+ $job = $client->lookup_job($job_id);
+ is $job->priority, 1;
+
+ $job->completed;
+ };
};
subtest 'error case' => sub {

0 comments on commit 3615d42

Please sign in to comment.