Skip to content

Instantly share code, notes, and snippets.

@kwakwaversal
Last active September 18, 2017 14:32
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 kwakwaversal/c4a59332bda0da15e766e6b69b2bd1ce to your computer and use it in GitHub Desktop.
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
#!/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