NAME
Cantella::Worker::Role::Beanstalk - Fetch Cantella::Worker jobs from beanstalkd
SYNOPSIS
package TestWorkerPool;
use Try::Tiny;
use Moose;
with(
'Cantella::Worker::Role::Worker',
'Cantella::Worker::Role::Beanstalk'
);
sub work {
my ($self, $job) = @_;
my @args = $job->args;
try {
if( do_something(@args) ){
$job->delete; #work done successfully
} else {
$job->release({delay => 10}); #let's try again in 10 seconds
}
} catch {
$job->bury; #job failed, bury it and log to file
$self->logger->error("Burying job ".$job->id." due to error: '$_'");
};
}
ATTRIBUTES
beanstalk_clients
Read-only, required, ArrayRef of Beanstalk::Client instances.
reserve_timeout
Read-only integer. The reserve timeout will be passed on to Beanstalk::Client's reserve
method, and signals how long, in seconds, the client should wait for a job to become available before timing out and trying the next client in the pool.
WARNING: If you only have one Beanstalk server, you might be tempted to set not time out. Don't do this. By setting no timeout, the reserve command will block all other events, including signal handlers. Instead, it is suggested that the reserve_timeout
is set to something that is resonable for you workload and the load of your beanstalkd process.
max_tries
Read-only, Integer. After a job has been reserved more than max_tries
, it will be deleted and not attempted again.
delete_on_max_tries
Reas-only boolean. If delet_on_max_tries
is set to true and any job exceeds max_tries
, the job will be deleted from the pool, otherwise the job will be bury
ed. The value defaults to false. This attribue has no effect unless max_tries
is set.
METHODS
get_work
Will attempt to reserve a job from all of the clients and return it.
_start
The _start
method is extended to disconnect and reconnect to the beanstalk servers. This ensures that if a client instance is passed in as an argument prior to a fork when using Cantella::Worker::Manager::Prefork, the connection works correctly in the child.
SEE ALSO
Cantella::Worker::Manager::Prefork, Cantella::Worker::Role::Worker
AUTHOR
Guillermo Roditi (groditi) <groditi@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2009-2010 by Guillermo Roditi. This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.