Minion::Worker(3)

๐ŸŒธ Minion::Worker โ€” the Minion worker page, bestie edition ๐ŸŒธ

okay so this is Minion::Worker(3), straight out of the User Contributed Perl Documentation, and I am so excited to walk you through it ๐Ÿ’–


โœจ NAME โœจ

Minion::Worker โ€” it's literally a Minion worker. that's the whole vibe. ๐Ÿซถ


โœจ SYNOPSIS โœจ

like, the tiniest little taste:

use Minion::Worker;

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

look at her. iconic. no notes. ๐Ÿ’…


โœจ DESCRIPTION โœจ

Minion::Worker performs jobs for Minion. that's it, that's the job (literally), and it does it beautifully. ๐Ÿ‘‘


๐Ÿšฆ WORKER SIGNALS ๐Ÿšฆ

the Minion::Worker process can be controlled at runtime with the following signals. yes bestie, you can โœจsignalโœจ her.

INT, TERM

Stop gracefully after finishing the current jobs. she's a lady, she finishes what she started. ๐ŸŽ€

QUIT

Stop immediately without finishing the current jobs. no thoughts, no cleanup, just gone ๐Ÿ’€


๐Ÿฆ‹ JOB SIGNALS ๐Ÿฆ‹

the job processes spawned by the Minion::Worker process can be controlled at runtime with the following signals. so this is the children, not the worker herself, ok?

INT, TERM

This signal starts out with the operating system default and allows for jobs to install a custom signal handler to stop gracefully. so like, it's giving "we could be graceful, but only if the job sets that up" โœจ

USR1, USR2

These signals start out being ignored and allow for jobs to install custom signal handlers. they're just sitting there, minding their business, waiting for someone to care ๐Ÿ™ˆ


๐ŸŽ€ EVENTS ๐ŸŽ€

Minion::Worker inherits all events from Mojo::EventEmitter and can emit the following new ones. it's giving main character energy, fr fr.

busy

$worker->on(busy => sub ($worker) {
  ...
});

Emitted in the worker process when it is performing the maximum number of jobs in parallel. she's booked, she's busy, she's thriving. ๐Ÿ’…

$worker->on(busy => sub ($worker) {
  my $max = $worker->status->{jobs};
  say "Performing $max jobs.";
});

dequeue

$worker->on(dequeue => sub ($worker, $job) {
  ...
});

Emitted in the worker process after a job has been dequeued. new job just dropped ๐Ÿ“

$worker->on(dequeue => sub ($worker, $job) {
  my $id = $job->id;
  say "Job $id has been dequeued.";
});

wait

$worker->on(wait => sub ($worker) {
  ...
});

Emitted in the worker process before it tries to dequeue a job. the "anyone? anyone?" era ๐Ÿ˜ญ

$worker->on(wait => sub ($worker) {
  my $max = $worker->status->{dequeue_timeout};
  say "Waiting up to $max seconds for a new job.";
});

๐Ÿ’œ ATTRIBUTES ๐Ÿ’œ

Minion::Worker implements the following attributes. collect them all, bestie.

commands

my $commands = $worker->commands;
$worker      = $worker->commands({jobs => sub {...}});

Registered worker remote control commands. yes, you can remote control her. slay. ๐ŸŽฎ

id

my $id  = $worker->id;
$worker = $worker->id($id);

Worker id. her little name tag. ๐Ÿท๏ธ

minion

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

Minion object this worker belongs to. her home base. ๐Ÿ 

status

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. (and yes, that code snippet is exactly how the page has it โ€” I am not touching it, no cap ๐Ÿ˜ญ)


๐Ÿ‘‘ METHODS ๐Ÿ‘‘

Minion::Worker inherits all methods from Mojo::EventEmitter and implements the following new ones.

add_command

$worker = $worker->add_command(jobs => sub {...});

Register a worker remote control command.

$worker->add_command(foo => sub ($worker, @args) {
  ...
});

dequeue

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. glow-up arc: inactive โžก๏ธ active โœจ

These options are currently available:

  • id
id => '10023'

Dequeue a specific job. this one. right here. ๐Ÿ‘€

  • min_priority
min_priority => 3

Do not dequeue jobs with a lower priority. it's giving standards. ๐Ÿ’…

  • queues
queues => ['important']

One or more queues to dequeue jobs from, defaults to "default".

  • tasks
tasks => ['foo', 'bar']

One or more tasks to dequeue jobs from, defaults to all tasks.

info

my $info = $worker->info;

Get worker information. the โœจreceiptsโœจ.

# 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. her current roster ๐Ÿซถ

  • notified
notified => 784111777

Epoch time worker sent the last heartbeat. still alive, still thriving ๐Ÿ’–

  • 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. oversharing is self-care, bestie. ๐Ÿฆ‹

new

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. she's born, she's already subscribed, she naps. iconic. ๐Ÿ˜ด

process_commands

$worker = $worker->process_commands;

Process worker remote control commands.

register

$worker = $worker->register;

Register worker or send heartbeat to show that this worker is still alive. "not me checking in to say I'm still here" ๐Ÿ’…

run

$worker->run;

Run worker and wait for "WORKER SIGNALS". this is the big one, the main event, the finale ๐ŸŒˆ

# Start a worker for a special named queue
my $worker = $minion->worker;
$worker->status->{queues} = ['important'];
$worker->run;

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 (not including spare 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).

  • spare
spare => 2

Number of spare worker processes to reserve for high priority jobs, defaults to 1.

  • spare_min_priority
spare_min_priority => 7

Minimum priority of jobs to use spare worker processes for, defaults to 1.

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. zero = nap time, and she will finish her plate first, respectfully ๐Ÿฝ๏ธ

  • 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. immediately means IMMEDIATELY, no wrap-up speech ๐Ÿ’€

unregister

$worker = $worker->unregister;

Unregister worker. she's logging off, closing the app, going to bed ๐ŸŒ™


๐Ÿงš SEE ALSO ๐Ÿงš

Minion, Minion::Guide, <https://minion.pm>, Mojolicious::Guides, <https://mojolicious.org>.


and that's the whole page, bestie!! this one came from perl v5.42.0, dated 2026-01-17, and it lives in the Minion::Worker(3) section โ€” go forth and run workers, ily ๐Ÿ’–โœจ๐ŸŽ€๐Ÿฆ‹๐ŸŒธ๐Ÿ’…๐Ÿซถ

๐Ÿ“ฆ where this page comes from