Jonk::Cookbook::ErrorHandling - error handling enqueue and dequeue
enqueue script:
#! perl use strict; use warnings; use DBI; use Jonk; my $dbh = DBI->connect('dbi:mysql:test','user','pass'); my $jonk = Jonk->new($dbh); my $job_id = $jonk->insert('worker_key','job_data_here'); if ($jonk->errstr) { die $jonk->errstr; }
worker script:
#! 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 => {functions => [qw/worker_key/]}); while (1) { my $job = $jonk->find_job; if ($jonk->errstr) { die $jonk->errstr; } if ($job) { Your::Worker->work($job); } else { sleep(3); # wait for 3 sec. } }
To install Jonk, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Jonk
CPAN shell
perl -MCPAN -e shell install Jonk
For more information on module installation, please visit the detailed CPAN module installation guide.