Added initial Minion support and example test job

This commit is contained in:
Thomas Bloor 2018-03-20 19:24:48 +00:00
parent cc6ea41ce5
commit 1302f9e843
No known key found for this signature in database
GPG key ID: 4657C7EBE42CC5CC
6 changed files with 101 additions and 0 deletions

View file

@ -0,0 +1,37 @@
package Pear::LocalLoop::Plugin::Minion;
use Mojo::Base 'Mojolicious::Plugin';
use Mojo::Loader qw/ find_modules load_class /;
sub register {
my ( $plugin, $app, $cong ) = @_;
if ( defined $app->config->{minion} ) {
$app->log->debug('Setting up Minion');
$app->plugin('Minion' => $app->config->{minion} );
my $job_namespace = __PACKAGE__ . '::Job';
my @modules = find_modules $job_namespace;
for my $package ( @modules ) {
my ( $job ) = $package =~ /${job_namespace}::(.*)$/;
$app->log->debug( $package );
$app->log->debug( $job );
load_class $package;
$app->minion->add_task(
$job => sub {
my ( $job, @args ) = @_;
my $job_runner = $package->new(
job => $job,
);
$job_runner->run( @args );
}
);
}
$app->minion->enqueue('test' => [ 'test arg 1', 'test_arg 2' ] );
} else {
$app->log->debug('No Minion Config');
}
}
1;

View file

@ -0,0 +1,15 @@
package Pear::LocalLoop::Plugin::Minion::Job::test;
use Mojo::Base -base;
has [ qw/ job / ];
sub run {
my ( $self, @args ) = @_;
$self->job->app->log->debug( 'Testing Job' );
for my $arg ( @args ) {
$self->job->app->log->debug( $arg );
}
}
1;