Skip to content

Instantly share code, notes, and snippets.

@worldmind
Last active March 11, 2021 06:43
Show Gist options
  • Save worldmind/21eeaecc8b1a0c22388424afed1786ff to your computer and use it in GitHub Desktop.
Save worldmind/21eeaecc8b1a0c22388424afed1786ff to your computer and use it in GitHub Desktop.
Minion example
#!/usr/bin/perl -w
use Mojolicious::Lite;
use Minion;
# run app: morbo minion-example.pl
# run worker: perl minion-example.pl minion worker
# enqueue job: curl 'http://127.0.0.1:3000/do?msg=hello'
# show job status: perl minion-example.pl minion job 1
plugin Minion => { SQLite => 'sqlite:test.db' };
get '/do' => sub {
my $c = shift;
my $msg = $c->param('msg') // 'HELLO';
my $id = app->minion->enqueue(do_things => [$msg]);
$c->render(text => "Task id:$id is enqueued$/");
};
app->minion->add_task(do_things => sub {
my ($job, $msg) = @_;
sleep 3;
say $msg;
$job->on(finished => sub {
my ($job, $result) = @_;
my $id = $job->id;
say "Job id: $id is finished. Result: $result";
});
$job->finish($msg);
});
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment