NAME

Minion - Job queue

SYNOPSIS

use Minion;

# Add tasks
my $minion = Minion->new('mongodb://localhost:27017');
$minion->add_task(something_slow => sub {
  my ($job, @args) = @_;
  sleep 5;
  say 'This is a background worker process.';
});

# Enqueue jobs (data gets BSON serialized)
$minion->enqueue(something_slow => ['foo', 'bar']);
$minion->enqueue(something_slow => [1, 2, 3]);

# Perform jobs automatically for testing
$minion->auto_perform(1);
$minion->enqueue(something_slow => ['foo', 'bar']);

# Build more sophisticated workers
my $worker = $minion->repair->worker->register;
if (my $job = $worker->dequeue) { $job->perform }
$worker->unregister;

DESCRIPTION

Minion is a Mango job queue for the Mojolicious real-time web framework.

Background worker processes are usually started with the command Minion::Command::minion::worker, which becomes automatically available when an application loads the plugin Mojolicious::Plugin::Minion.

$ ./myapp.pl minion worker

Note that this whole distribution is EXPERIMENTAL and will change without warning!

Many features are still incomplete or missing, so you should wait for a stable 1.0 release before using any of the modules in this distribution in a production environment.

ATTRIBUTES

Minion implements the following attributes.

app

my $app = $minion->app;
$minion = $minion->app(MyApp->new);

Application for job queue, defaults to a Mojo::HelloWorld object.

auto_perform

my $bool = $minion->auto_perform;
$minion  = $minion->auto_perform($bool);

Perform jobs automatically when a new one has been enqueued with "enqueue", very useful for testing.

jobs

my $jobs = $minion->jobs;
$minion  = $minion->jobs(Mango::Collection->new);

Mango::Collection object for jobs collection, defaults to one based on "prefix".

mango

my $mango = $minion->mango;
$minion   = $minion->mango(Mango->new);

Mango object used to store collections.

prefix

my $prefix = $minion->prefix;
$minion    = $minion->prefix('foo');

Prefix for collections, defaults to minion.

tasks

my $tasks = $minion->tasks;
$minion   = $minion->tasks({foo => sub {...}});

Registered tasks.

workers

my $workers = $minion->workers;
$minion     = $minion->workers(Mango::Collection->new);

Mango::Collection object for workers collection, defaults to one based on "prefix".

METHODS

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

add_task

$minion = $minion->add_task(foo => sub {...});

Register a new task.

enqueue

my $oid = $minion->enqueue('foo');
my $oid = $minion->enqueue(foo => [@args]);
my $oid = $minion->enqueue(foo => [@args] => {priority => 1});

Enqueue a new job with inactive state.

These options are currently available:

after
after => bson_time((time + 1) * 1000)

Perform job only after this point in time.

priority
priority => 5

Job priority.

job

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

Get Minion::Job object without making any changes to the actual job or return undef if job does not exist.

new

my $minion = Minion->new;
my $minion = Minion->new('mongodb://127.0.0.1:27017');

Construct a new Minion object and pass connection string to "mango" if necessary.

repair

$minion = $minion->repair;

Repair worker registry and job queue.

stats

my $stats = $minion->stats;

Get statistics for jobs and workers.

worker

my $worker = $minion->worker;

Build Minion::Worker object.

AUTHOR

Sebastian Riedel, sri@cpan.org.

COPYRIGHT AND LICENSE

Copyright (C) 2014, Sebastian Riedel.

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.

SEE ALSO

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