Minion::Worker - Minion worker
use Minion::Worker; my $worker = Minion::Worker->new(minion => $minion);
Minion::Worker performs jobs for Minion.
Minion::Worker inherits all events from Mojo::EventEmitter and can emit the following new ones.
$worker->on(dequeue => sub { my ($worker, $job) = @_; ... });
Emitted in the worker process after a job has been dequeued.
$worker->on(dequeue => sub { my ($worker, $job) = @_; my $id = $job->id; say "Job $id has been dequeued."; });
Minion::Worker implements the following attributes.
my $commands = $worker->commands; $worker = $worker->commands({jobs => sub {...}});
Registered worker remote control commands.
my $id = $worker->id; $worker = $worker->id($id);
Worker id.
my $minion = $worker->minion; $worker = $worker->minion(Minion->new);
Minion object this worker belongs to.
my $status = $worker->status; $worker = $worker->status({queues => ['default', 'important']);
Status information to share every time "register" is called.
Minion::Worker inherits all methods from Mojo::EventEmitter and implements the following new ones.
$worker = $worker->add_command(jobs => sub {...});
Register a worker remote control command.
$worker->add_command(foo => sub { my ($worker, @args) = @_; ... });
my $job = $worker->dequeue(0.5); my $job = $worker->dequeue(0.5 => {queues => ['important']});
Wait a given amount of time in seconds for a job, dequeue Minion::Job object and transition from inactive to active state, or return undef if queues were empty.
inactive
active
undef
These options are currently available:
id => '10023'
Dequeue a specific job.
queues => ['important']
One or more queues to dequeue jobs from, defaults to default.
default
my $info = $worker->info;
Get worker information.
# Check worker host my $host = $worker->info->{host};
These fields are currently available:
host => 'localhost'
Worker host.
jobs => ['10023', '10024', '10025', '10029']
Ids of jobs the worker is currently processing.
notified => 784111777
Epoch time worker sent the last heartbeat.
pid => 12345
Process id of worker.
started => 784111777
Epoch time worker was started.
status => {queues => ['default', 'important']}
Hash reference with whatever status information the worker would like to share.
$worker = $worker->process_commands;
Process worker remote control commands.
$worker = $worker->register;
Register worker or send heartbeat to show that this worker is still alive.
$worker = $worker->unregister;
Unregister worker.
Minion, Mojolicious::Guides, http://mojolicious.org.
To install Minion, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Minion
CPAN shell
perl -MCPAN -e shell install Minion
For more information on module installation, please visit the detailed CPAN module installation guide.