Created role for Minion Jobs to make dev easier
This commit is contained in:
parent
a53479c6c8
commit
3514a9e0ed
4 changed files with 29 additions and 6 deletions
|
@ -7,15 +7,16 @@ sub register {
|
|||
my ( $plugin, $app, $cong ) = @_;
|
||||
|
||||
if ( defined $app->config->{minion} ) {
|
||||
$app->log->debug('Setting up Minion');
|
||||
$app->log->debug('Setting up Minion tasks');
|
||||
$app->plugin('Minion' => $app->config->{minion} );
|
||||
|
||||
$app->log->debug('Loaded Minion Job packages:');
|
||||
|
||||
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 {
|
||||
|
|
12
lib/Pear/LocalLoop/Plugin/Minion/Job.pm
Normal file
12
lib/Pear/LocalLoop/Plugin/Minion/Job.pm
Normal file
|
@ -0,0 +1,12 @@
|
|||
package Pear::LocalLoop::Plugin::Minion::Job;
|
||||
use Mojo::Base -base;
|
||||
|
||||
has [ qw/ job / ];
|
||||
|
||||
has app => sub { shift->job->app };
|
||||
|
||||
sub run {
|
||||
die ( __PACKAGE__ . " must implement run sub" );
|
||||
}
|
||||
|
||||
1;
|
12
lib/Pear/LocalLoop/Plugin/Minion/Job/leaderboards_recalc.pm
Normal file
12
lib/Pear/LocalLoop/Plugin/Minion/Job/leaderboards_recalc.pm
Normal file
|
@ -0,0 +1,12 @@
|
|||
package Pear::LocalLoop::Plugin::Minion::Job::leaderboards_recalc;
|
||||
use Mojo::Base 'Pear::LocalLoop::Plugin::Minion::Job';
|
||||
|
||||
sub run {
|
||||
my ( $self, @args ) = @_;
|
||||
|
||||
my $leaderboard_rs = $self->app->schema->resultset('Leaderboard');
|
||||
|
||||
$leaderboard_rs->recalculate_all;
|
||||
}
|
||||
|
||||
1;
|
|
@ -1,7 +1,5 @@
|
|||
package Pear::LocalLoop::Plugin::Minion::Job::test;
|
||||
use Mojo::Base -base;
|
||||
|
||||
has [ qw/ job / ];
|
||||
use Mojo::Base 'Pear::LocalLoop::Plugin::Minion::Job';
|
||||
|
||||
sub run {
|
||||
my ( $self, @args ) = @_;
|
||||
|
|
Reference in a new issue