Minion::Job(3)

πŸ’– Minion::Job β€” the whole vibe πŸ’–

okay bestie, welcome to Minion::Job (that's the Minion::Job(3) page from the User Contributed Perl Documentation, if you're keeping receipts) β€” it's a container for Minion jobs and honestly it's giving main character energy for your whole task pipeline ✨


✨ NAME ✨

Minion::Job β€” a Minion job. that's it. that's the name. iconic πŸ’…


🌸 SYNOPSIS 🌸

here's the whole setup, no cap:

package MyApp::Task::Foo;
use Mojo::Base 'Minion::Job', -signatures;

sub run ($self, @args) {

  # Magic here! :)
}

see that # Magic here! :)? that's you. that's your moment. go off 🧚


πŸ¦‹ DESCRIPTION πŸ¦‹

Minion::Job is a container for Minion jobs. literally just a little box that holds one job and all its hopes and dreams 🫢


🌈 EVENTS 🌈

Minion::Job inherits all events from Mojo::EventEmitter and can emit the following new ones. these are your little notification pings, bestie πŸ””

πŸ’œ cleanup

$job->on(cleanup => sub ($job) {
  ...
});

Emitted in the process performing this job right before the process will exit. like the last text before you go to sleep πŸŒ™

$job->on(cleanup => sub ($job) {
  $job->app->log->debug("Process $$ is about to exit");
});

πŸ’œ failed

$job->on(failed => sub ($job, $err) {
  ...
});

Emitted in the worker process managing this job or the process performing it, after it has transitioned to the "failed" state. it's giving not-your-day 😭

$job->on(failed => sub ($job, $err) {
  say "Something went wrong: $err";
});

πŸ’œ finish

$job->on(finish => sub ($job) {
  ...
});

Emitted in the process performing this job if the task was successful. slay βœ…

$job->on(finish => sub ($job) {
  my $id   = $job->id;
  my $task = $job->task;
  $job->app->log->debug(qq{Job "$id" was performed with task "$task"});
});

πŸ’œ finished

$job->on(finished => sub ($job, $result) {
  ...
});

Emitted in the worker process managing this job or the process performing it, after it has transitioned to the "finished" state. she's done, she's healed, periodt πŸ’…

$job->on(finished => sub ($job, $result) {
  my $id = $job->id;
  say "Job $id is finished.";
});

πŸ’œ reap

$job->on(reap => sub ($job, $pid) {
  ...
});

Emitted in the worker process managing this job, after the process performing it has exited. rip bozo (affectionate) πŸ™ˆ

$job->on(reap => sub ($job, $pid) {
  my $id = $job->id;
  say "Job $id ran in process $pid";
});

πŸ’œ spawn

$job->on(spawn => sub ($job, $pid) {
  ...
});

Emitted in the worker process managing this job, after a new process has been spawned for processing. baby process is born 🐣

$job->on(spawn => sub ($job, $pid) {
  my $id = $job->id;
  say "Job $id running in process $pid";
});

πŸ’œ start

$job->on(start => sub ($job) {
  ...
});

Emitted in the process performing this job, after it has been spawned. the way that this is literally the opening scene of the job's life 😭

$job->on(start => sub ($job) {
  $0 = $job->id;
});

πŸŽ€ ATTRIBUTES πŸŽ€

Minion::Job implements the following attributes. these are the little properties she carries around in her bag πŸ‘œ

πŸ“ args

my $args = $job->args;
$job     = $job->args([]);

Arguments passed to task. the receipts, the lore 🧾

πŸ“ id

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

Job id. her name tag πŸ’–

πŸ“ minion

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

Minion object this job belongs to. her home base 🏠

πŸ“ retries

my $retries = $job->retries;
$job        = $job->retries(5);

Number of times job has been retried. how many second chances she's gotten πŸ”

πŸ“ task

my $task = $job->task;
$job     = $job->task('foo');

Task name. what she's actually here to do ✨


πŸ”₯ METHODS πŸ”₯

Minion::Job inherits all methods from Mojo::EventEmitter and implements the following new ones. buckle up buttercup, this is the long section 😀

πŸ‘‘ app

my $app = $job->app;

Get application from "app" in Minion. also here's the long version, iykyk:

# Longer version
my $app = $job->minion->app;

πŸ‘‘ execute

my $err = $job->execute;

Perform job in this process and return "undef" if the task was successful or an exception otherwise. Note that this method should only be used to implement custom workers.

# Perform job in foreground
if (my $err = $job->execute) { $job->fail($err) }
else                         { $job->finish }

πŸ‘‘ fail

my $bool = $job->fail;
my $bool = $job->fail('Something went wrong!');
my $bool = $job->fail({whatever => 'Something went wrong!'});

Transition from "active" to "failed" state with or without a result, and if there are attempts remaining, transition back to "inactive" with a delay based on "backoff" in Minion. she's not down bad, she's just resting πŸ’€

πŸ‘‘ finish

my $bool = $job->finish;
my $bool = $job->finish('All went well!');
my $bool = $job->finish({whatever => 'All went well!'});

Transition from "active" to "finished" state with or without a result. ate and left no crumbs 🌟

πŸ‘‘ info

my $info = $job->info;

Get job information. the whole gossip file πŸ“‹

# Check job state
my $state = $job->info->{state};

# Get job metadata
my $progress = $job->info->{notes}{progress};

# Get job result
my $result = $job->info->{result};

These fields are currently available:

  • args β€” args => ['foo', 'bar'] β€” Job arguments.
  • attempts β€” attempts => 25 β€” Number of times performing this job will be attempted.
  • children β€” children => ['10026', '10027', '10028'] β€” Jobs depending on this job.
  • created β€” created => 784111777 β€” Epoch time job was created.
  • delayed β€” delayed => 784111777 β€” Epoch time job was delayed to.
  • expires β€” expires => 784111777 β€” Epoch time job is valid until before it expires.
  • finished β€” finished => 784111777 β€” Epoch time job was finished.
  • lax β€” lax => 0 β€” Existing jobs this job depends on may also have failed to allow for it to be processed.
  • notes β€” notes => {foo => 'bar', baz => [1, 2, 3]} β€” Hash reference with arbitrary metadata for this job.
  • parents β€” parents => ['10023', '10024', '10025'] β€” Jobs this job depends on.
  • priority β€” priority => 3 β€” Job priority.
  • queue β€” queue => 'important' β€” Queue name.
  • result β€” result => 'All went well!' β€” Job result.
  • retried β€” retried => 784111777 β€” Epoch time job has been retried.
  • retries β€” retries => 3 β€” Number of times job has been retried.
  • started β€” started => 784111777 β€” Epoch time job was started.
  • state β€” state => 'inactive' β€” Current job state, usually "active", "failed", "finished" or "inactive".
  • task β€” task => 'foo' β€” Task name.
  • time β€” time => 784111777 β€” Server time.
  • worker β€” worker => '154' β€” Id of worker that is processing the job.

πŸ‘‘ is_finished

my $bool = $job->is_finished;

Check if job performed with "start" is finished. Note that this method should only be used to implement custom workers.

πŸ‘‘ kill

$job->kill('INT');

Send a signal to job performed with "start". Note that this method should only be used to implement custom workers. it's giving "we need to talk" 😬

πŸ‘‘ note

my $bool = $job->note(mojo => 'rocks', minion => 'too');

Change one or more metadata fields for this job. Setting a value to "undef" will remove the field. The new values will get serialized by "backend" in Minion (often with Mojo::JSON), so you shouldn't send objects and be careful with binary data, nested data structures with hash and array references are fine though.

fr fr on the binary data thing, bestie β€” don't do it, it's not worth the drama 😭
# Share progress information
$job->note(progress => 95);

# Share stats
$job->note(stats => {utime => '0.012628', stime => '0.002429'});

πŸ‘‘ parents

my $parents = $job->parents;

Return a Mojo::Collection object containing all jobs this job depends on as Minion::Job objects. her ancestors, her lineage πŸ‘‘

# Check parent state
for my $parent ($job->parents->each) {
  my $info = $parent->info;
  say "$info->{id}: $info->{state}";
}

πŸ‘‘ perform

$job->perform;

Perform job in new process and wait for it to finish. Note that this method should only be used to implement custom workers.

πŸ‘‘ pid

my $pid = $job->pid;

Process id of the process spawned by "start" if available. Note that this method should only be used to implement custom workers.

πŸ‘‘ remove

my $bool = $job->remove;

Remove "failed", "finished" or "inactive" job from queue. she's out, she's gone, blocked 🚫

πŸ‘‘ retry

my $bool = $job->retry;
my $bool = $job->retry({delay => 10});

Transition job back to "inactive" state, already "inactive" jobs may also be retried to change options. second chance era 🫢

These options are currently available:

  • attempts β€” attempts => 25 β€” Number of times performing this job will be attempted.
  • delay β€” delay => 10 β€” Delay job for this many seconds (from now), defaults to 0.
  • expire β€” expire => 300 β€” Job is valid for this many seconds (from now) before it expires.
  • lax β€” lax => 1 β€” Existing jobs this job depends on may also have transitioned to the "failed" state to allow for it to be processed, defaults to "false".
  • parents β€” parents => [$id1, $id2, $id3] β€” Jobs this job depends on.
  • priority β€” priority => 5 β€” Job priority.
  • queue β€” queue => 'important' β€” Queue to put job in.

πŸ‘‘ run

$job->run(@args);

Task to perform by this job. Meant to be overloaded in a subclass to create a custom task class.

⚠️ Note that this method is EXPERIMENTAL and might change without warning! ⚠️

like she said what she said but she might change her mind, no cap πŸ’…

πŸ‘‘ start

$job = $job->start;

Perform job in new process, but do not wait for it to finish. Note that this method should only be used to implement custom workers.

# Perform two jobs concurrently
$job1->start;
$job2->start;
my ($first, $second);
sleep 1
  until $first ||= $job1->is_finished and $second ||= $job2->is_finished;

multitasking queen behavior πŸ‘Έ

πŸ‘‘ stop

$job->stop;

Stop job performed with "start" immediately. Note that this method should only be used to implement custom workers. abrupt but necessary, we've all been there 😭


🌟 SEE ALSO 🌟

go read these too, bestie, they're the extended universe:


and that's the whole page!! πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«Ά this beauty ships as perl v5.42.0, dated 2026-01-17, and it's the Minion::Job(3) manpage β€” so go forth and run your tasks, you absolute icon πŸ‘‘πŸ’œ

πŸ“¦ where this page comes from