Last active
December 14, 2017 20:36
-
-
Save scottw/18a95ddaab44837e92526cdbc93d4275 to your computer and use it in GitHub Desktop.
Minion job injector and worker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 $_"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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