Cantella::Worker::Role::Worker - Polling POE worker
package TestWorkerPool; use Moose; with 'Cantella::Worker::Role::Worker'; my @work_stack = ( 1 .. 10); sub get_work { my $self = shift; if( @work_stack ){ return shift @work_stack; } else { $self->shutdown; return; } } sub work { my ($self, $args) = @_; sleep(1); }
$work_data
Should return undef if there's no work avaliable and a single defined scalar representing the inputs to the work if there is.
undef
Do whatever!
Read-only Log::Dispatch instance. Defaults to a device that logs to Null. This attribute can coerce from a hash or array reference, see MooseX::Types::Log::Dispatch for details.
Read-write integer. The number of seconds to wait between poll events. Will default to 2 seconds.
poll
2
Read-only string. This is the alias of the session managing the workers and will default to a UUID string by default.
\%args
after BUILD Sets up the polling session and its event handlers.
after BUILD
Begin the event loop
Stop polling for work.
Resume polling for work.
Stop polling for work and end the session after current jobs are done.
The following methods are POE event handlers. They are not meant to be called directly and will not work if you do. When applicable, arguments will be passed into the methods in ARG0, ARG1, etc.
Poll for work. If we find work, schedule another poll event due to execute after the work event. If no jobs are found, schedule the next poll for interval seconds in the future. This ensures that the worker will always be busy while there is work, but will control it's polling for work when there isn't any available.
interval
work
$work_info
Do this one job.
_start
Start the polling process
_pause
$until
Pause the polling process until $until
_resume
Resume the polling process
shutdown
Remove all alarms and wait for the session to die
Cantella::Worker::Manager::Prefork, Cantella::Worker::Role::Beanstalk
Guillermo Roditi (groditi) <groditi@cpan.org>
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.
To install Cantella::Worker, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Cantella::Worker
CPAN shell
perl -MCPAN -e shell install Cantella::Worker
For more information on module installation, please visit the detailed CPAN module installation guide.