Last active
September 18, 2017 14:32
-
-
Save kwakwaversal/c4a59332bda0da15e766e6b69b2bd1ce to your computer and use it in GitHub Desktop.
Minion task to access MyApp to reduce boilerplate for any standalone Minion tasks #mojo #perl
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 Mojolicious::Lite; | |
use FindBin; | |
BEGIN { unshift @INC, "$FindBin::Bin/../lib" } | |
use MyApp; | |
# Load in MyApp so we can utilise the config and database connections without | |
# adding unnecessary boilerplate. | |
my $myapp = MyApp->new; | |
# Load minion using the config obtained above | |
plugin Minion => {Pg => $myapp->config->{jobs}->{minion}}; | |
# Task to do some job | |
app->minion->add_task( | |
do_some_job => sub { | |
my ($job, $args) = @_; | |
print "------\n" x 5; | |
print "TRYING JOB"; | |
print "------\n" x 5; | |
# Access the db from our loaded app | |
my $company = $myapp->db->resultset('Company')->single({name => 'kwa'}); | |
$job->fail; | |
$job->retry; | |
} | |
); | |
app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment