Skip to content

Instantly share code, notes, and snippets.

@brianmed
Created April 7, 2016 05:50
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 brianmed/cb1a7f268d26c8a3f172d0ec34bee09c to your computer and use it in GitHub Desktop.
Save brianmed/cb1a7f268d26c8a3f172d0ec34bee09c to your computer and use it in GitHub Desktop.
Run some commands via Minion
#!/opt/perl
use Mojolicious::Lite;
app->log->level("debug");
plugin Minion => { SQLite => 'sqlite:test.db' };
app->minion->add_task(run => sub {
my ($job, @args) = @_;
my ($ret, $msg);
$job->app->log->info("Before $args[0]");
eval {
$ret = system(@args) == 0 or die("system: $args[0]: $!");
};
$job->app->log->info("After $args[0]");
$job->finish({ ret => $ret, msg => $msg // "Fine" });
});
app->start;
package Mojolicious::Command::run_commands;
use Mojo::Base 'Mojolicious::Command';
has description => 'Run commands';
has usage => "Usage: APPLICATION run_commands\n";
sub run {
my ($self, @args) = @_;
# $args[0] is the file
say($self->app->minion->enqueue(run => ["echo", "joy"]));
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment