Browse files

add retry case Cookbook.

  • Loading branch information...
1 parent eeac588 commit 81d22bf487bf0083be60a66039aa5fa3ef2831a4 @nekokak committed Jan 26, 2011
Showing with 42 additions and 0 deletions.
  1. +2 −0 lib/Jonk/Cookbook.pod
  2. +40 −0 lib/Jonk/Cookbook/RetryJob.pod
View
2 lib/Jonk/Cookbook.pod
@@ -12,4 +12,6 @@ L<Jonk::Cookbook::DequeueSpecificJob> - dequeue specific job.
L<Jonk::Cookbook::ErrorHandling> - error handling enqueue and dequeue.
+L<Jonk::Cookbook::RetryJob> - retry job with wait few minitus.
+
=cut
View
40 lib/Jonk/Cookbook/RetryJob.pod
@@ -0,0 +1,40 @@
+=head1 NAME
+
+Jonk::Cookbook::RetryJob - retry job with wait few minitus
+
+=head1 USAGE
+
+ #! perl
+ use strict;
+ use warnings;
+ use DBI;
+ use Jonk
+ use Your::Worker;
+
+ my $dbh = DBI->connect('dbi:mysql:test','user','pass');
+ my $jonk = Jonk->new($dbh);
+ my $job_id = $jonk->enqueue('worker_key','job_data_here');
+
+ while (1) {
+ my $job = $jonk->find_job;
+
+ eval {
+ Your::Worker->work($job);
+ };
+ if ($@) {
+ if ($job->retry_cnt >= 5) {
+ $job->aborted();
+ } else {
+ $job->failed(
+ {
+ retry_delay => ($job->retry_cnt*30),
+ }
+ );
+ }
+ }
+
+ sleep(3); # wait for 3 sec.
+ }
+
+=cut
+

0 comments on commit 81d22bf

Please sign in to comment.