NAME

Minion::Job - Minion job

SYNOPSIS

use Minion::Job;

my $job = Minion::Job->new(id => $oid, minion => $minion, task => 'foo');

DESCRIPTION

Minion::Job is a container for Minion jobs.

EVENTS

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

failed

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

Emitted after this job transitioned to the failed state.

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

finished

$job->on(finished => sub {
  my $job = shift;
  ...
});

Emitted after this job transitioned to the finished state.

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

ATTRIBUTES

Minion::Job implements the following attributes.

args

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

Arguments passed to task.

id

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

Job id.

minion

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

Minion object this job belongs to.

task

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

Task name.

METHODS

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

app

my $app = $job->app;

Get application from "app" in Minion.

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

created

my $epoch = $job->created;

Time this job was created in floating seconds since the epoch.

delayed

my $epoch = $job->delayed;

Time this job was delayed to in floating seconds since the epoch.

error

my $err = $job->error;

Get error for failed job.

fail

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

Transition from active to failed state.

finish

my $bool = $job->finish;

Transition from active to finished state.

finished

my $epoch = $job->finished;

Time this job transitioned from active to failed or finished in floating seconds since the epoch.

perform

$job->perform;

Perform job in new process and wait for it to finish.

priority

my $priority = $job->priority;

Get job priority.

remove

my $bool = $job->remove;

Remove failed, finished or inactive job from queue.

restart

my $bool = $job->restart;

Transition from failed or finished state back to inactive.

restarted

my $epoch = $job->restarted;

Time this job last transitioned from failed or finished back to inactive in floating seconds since the epoch.

restarts

my $num = $job->restarts;

Get number of times this job has been restarted.

started

my $epoch = $job->started;

Time this job transitioned from inactive to active in floating seconds since the epoch.

state

my $state = $job->state;

Get current state of job, usually active, failed, finished or inactive.

SEE ALSO

Minion, Mojolicious::Guides, http://mojolicio.us.