GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Minion::Worker(3) User Contributed Perl Documentation Minion::Worker(3)
 

Minion::Worker - Minion worker

  use Minion::Worker;
  my $worker = Minion::Worker->new(minion => $minion);

Minion::Worker performs jobs for Minion.

The Minion::Worker process can be controlled at runtime with the following signals.

Stop gracefully after finishing the current jobs.

Stop immediately without finishing the current jobs.

The job processes spawned by the Minion::Worker process can be controlled at runtime with the following signals.

This signal starts out with the operating system default and allows for jobs to install a custom signal handler to stop gracefully.

These signals start out being ignored and allow for jobs to install custom signal handlers.

Minion::Worker inherits all events from Mojo::EventEmitter and can emit the following new ones.

  $worker->on(busy => sub {
    my $worker = shift;
    ...
  });
Emitted in the worker process when it is performing the maximum number of jobs in parallel.
  $worker->on(busy => sub {
    my $worker = shift;
    my $max = $worker->status->{jobs};
    say "Performing $max jobs.";
  });

  $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.";
  });

  $worker->on(wait => sub {
    my $worker = shift;
    ...
  });
Emitted in the worker process before it tries to dequeue a job.
  $worker->on(wait => sub {
    my $worker = shift;
    my $max = $worker->status->{dequeue_timeout};
    say "Waiting up to $max seconds for a new job.";
  });

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 configure workers started with "run" and 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.
These options are currently available:
id
  id => '10023'
    
Dequeue a specific job.
queues
  queues => ['important']
    
One or more queues to dequeue jobs from, defaults to "default".

  my $info = $worker->info;
Get worker information.
  # Check worker host
  my $host = $worker->info->{host};
These fields are currently available:
host
  host => 'localhost'
    
Worker host.
jobs
  jobs => ['10023', '10024', '10025', '10029']
    
Ids of jobs the worker is currently processing.
notified
  notified => 784111777
    
Epoch time worker sent the last heartbeat.
pid
  pid => 12345
    
Process id of worker.
started
  started => 784111777
    
Epoch time worker was started.
status
  status => {queues => ['default', 'important']}
    
Hash reference with whatever status information the worker would like to share.

  my $worker = Minion::Worker->new;
  my $worker = Minion::Worker->new(status => {foo => 'bar'});
  my $worker = Minion::Worker->new({status => {foo => 'bar'}});
Construct a new Minion::Worker object and subscribe to "busy" event with default handler that sleeps for one second.

  $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->run;
Run worker and wait for "SIGNALS".
These "status" options are currently available:
command_interval
  command_interval => 20
    
Worker remote control command interval, defaults to 10.
dequeue_timeout
  dequeue_timeout => 5
    
Maximum amount time in seconds to wait for a job, defaults to 5.
heartbeat_interval
  heartbeat_interval => 60
    
Heartbeat interval, defaults to 300.
jobs
  jobs => 12
    
Maximum number of jobs to perform parallel in forked worker processes, defaults to 4.
queues
  queues => ['test']
    
One or more queues to get jobs from, defaults to "default".
repair_interval
  repair_interval => 3600
    
Repair interval, up to half of this value can be subtracted randomly to make sure not all workers repair at the same time, defaults to 21600 (6 hours).
These remote control "commands" are currently available:
jobs
  $minion->broadcast('jobs', [10]);
  $minion->broadcast('jobs', [10], [$worker_id]);
    
Instruct one or more workers to change the number of jobs to perform concurrently. Setting this value to 0 will effectively pause the worker. That means all current jobs will be finished, but no new ones accepted, until the number is increased again.
kill
  $minion->broadcast('kill', ['INT', 10025]);
  $minion->broadcast('kill', ['INT', 10025], [$worker_id]);
    
Instruct one or more workers to send a signal to a job that is currently being performed. This command will be ignored by workers that do not have a job matching the id. That means it is safe to broadcast this command to all workers.
stop
  $minion->broadcast('stop', [10025]);
  $minion->broadcast('stop', [10025], [$worker_id]);
    
Instruct one or more workers to stop a job that is currently being performed immediately. This command will be ignored by workers that do not have a job matching the id. That means it is safe to broadcast this command to all workers.

  $worker = $worker->unregister;
Unregister worker.

Minion, Mojolicious::Guides, <https://mojolicious.org>.
2018-09-22 perl v5.28.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.