Created
April 7, 2016 05:50
-
-
Save brianmed/cb1a7f268d26c8a3f172d0ec34bee09c to your computer and use it in GitHub Desktop.
Run some commands via Minion
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
#!/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