Where I work we use both Mojolicious and Minion daily, and I think they
are fantastic. Hats off to the development team!
In our use of Minion we routinely employ the 'failed' and 'finished'
events, but there are times when we might also like to take some action
with a 'start' event, and I'm having trouble getting even the simple
example script below to do anything with $job->on(start...). I suspect
I am either doing something stupid or fundamentally misunderstanding
what the 'start' event type is for and how it is to be used. Can anyone
comment on what I'm trying to do here? There seems to be no problem
with $job->on(finished...).
Thanks!
#!/usr/bin/env perl
use strict;
use warnings;
use Minion;
use Minion::Backend::SQLite;
use feature qw(say);
my $backend = Minion::Backend::SQLite->new('sqlite:test.db');
my $minion = Minion->new(SQLite => 'sqlite:minion.db');
# Add tasks
$minion->add_task(some_task => sub {
my ($job, @args) = @_;
$job->on(start => sub {
my $job = shift;
say 'This is a background worker process.';
});
$job->on(finished => sub {
my ($job, $results) = @_;
say for @$results, "\n";
});
$job->on(failed => sub {
my ($job, $error) = @_;
my $info = $job->info;
say "Failed: $info $error";
});
sleep 1;
$job->finish(\@args);
});
# Enqueue jobs
$minion->enqueue(some_task => [ 'Fry', 'Leela', 'Bender', 'Farnsworth' ]);
$minion->enqueue(some_task => [ 'Good news, everyone!' ] => {priority => 5});
$minion->enqueue(some_task => [ "Leela: I'm an alien, alright? Let's drop the subject.",
'Fry: Cool, an alien. Has your race taken over the planet?',
'Leela: No, I just work here.' ]);
$minion->perform_jobs;
# Start a worker
my $worker = $minion->worker;
$worker->status->{jobs} = 2;
$worker->run;
--
Brad Robertson
<
bradrob...@gmail.com>