Skip to content

Instantly share code, notes, and snippets.

@scottw
Last active December 14, 2017 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottw/18a95ddaab44837e92526cdbc93d4275 to your computer and use it in GitHub Desktop.
Save scottw/18a95ddaab44837e92526cdbc93d4275 to your computer and use it in GitHub Desktop.
Minion job injector and worker
#!/usr/bin/env perl
use Mojo::Base -strict;
use Minion;
my $minion = Minion->new(Pg => 'postgresql://postgres@/test');
for (1..10) {
$minion->enqueue('my-task', [name => "Number $_"], {delay => $_});
say STDERR "Injected $_";
}
[Thu Dec 14 13:31:15 2017] [info] Handling job 62 (name: Number 1)
[Thu Dec 14 13:31:15 2017] [info] Handling job 63 (name: Number 2)
[Thu Dec 14 13:31:15 2017] [info] Handling job 64 (name: Number 3)
[Thu Dec 14 13:31:15 2017] [info] Handling job 65 (name: Number 4)
[Thu Dec 14 13:31:20 2017] [info] Handling job 66 (name: Number 5)
[Thu Dec 14 13:31:20 2017] [info] Handling job 67 (name: Number 6)
[Thu Dec 14 13:31:20 2017] [info] Handling job 68 (name: Number 7)
[Thu Dec 14 13:31:20 2017] [info] Handling job 69 (name: Number 8)
[Thu Dec 14 13:31:20 2017] [info] Handling job 70 (name: Number 9)
[Thu Dec 14 13:31:25 2017] [info] Handling job 71 (name: Number 10)
#!/usr/bin/env perl
use Mojo::Base -strict;
use Minion;
use Mojo::Log;
my $minion = Minion->new(Pg => 'postgresql://postgres@/test');
my $log = Mojo::Log->new;
$minion->add_task(
'my-task' => sub {
my ($job, %args) = @_;
$log->info("Handling job " . $job->id . " (name: $args{name})");
$job->finish("All done with $args{name}");
}
);
$minion->worker->run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment