Merge remote-tracking branch 'origin/TBSliver/Minion-Tasks' into finn/minionimport
This commit is contained in:
commit
bc74496738
9 changed files with 127 additions and 1 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,6 +2,8 @@
|
||||||
myapp.conf
|
myapp.conf
|
||||||
hypnotoad.pid
|
hypnotoad.pid
|
||||||
*.db
|
*.db
|
||||||
|
*.db-wal
|
||||||
|
*.db-shm
|
||||||
*~
|
*~
|
||||||
/images
|
/images
|
||||||
*.swp
|
*.swp
|
||||||
|
|
35
README.md
35
README.md
|
@ -22,6 +22,41 @@ cpanm --installdeps . --with-feature postgres
|
||||||
PEAR_TEST_PG=1 prove -lr
|
PEAR_TEST_PG=1 prove -lr
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Minion
|
||||||
|
|
||||||
|
to set up minion support, you will need to create a database and user for
|
||||||
|
minion to connect to. In production his should be a PostgreSQL database,
|
||||||
|
however an SQLite db can be used in testing.
|
||||||
|
|
||||||
|
To use the SQLite version, run the following commands:
|
||||||
|
|
||||||
|
```
|
||||||
|
cpanm --installdeps --with-feature sqlite .
|
||||||
|
```
|
||||||
|
|
||||||
|
And then add the following to your configuration file:
|
||||||
|
|
||||||
|
```
|
||||||
|
minion => {
|
||||||
|
SQLite => 'sqlite:minion.db',
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
This will then use an SQLite db for the minion backend, at minion.db
|
||||||
|
|
||||||
|
|
||||||
|
## Example PostgreSQL setup
|
||||||
|
|
||||||
|
```
|
||||||
|
# Example commands - probably not the best ones
|
||||||
|
# TODO come back and improve these with proper ownership and DDL rights
|
||||||
|
sudo -u postgres createuser minion
|
||||||
|
sudo -u postgres createdb localloop_minion
|
||||||
|
sudo -u postgres psql
|
||||||
|
psql=# alter user minion with encrypted password 'abc123';
|
||||||
|
psql=# grant all privileges on database localloop_minion to minion;
|
||||||
|
```
|
||||||
|
|
||||||
# Dev notes
|
# Dev notes
|
||||||
|
|
||||||
## Local test database
|
## Local test database
|
||||||
|
|
4
cpanfile
4
cpanfile
|
@ -40,6 +40,10 @@ feature 'postgres', 'PostgreSQL Support' => sub {
|
||||||
requires 'Test::PostgreSQL';
|
requires 'Test::PostgreSQL';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
feature 'sqlite', 'SQLite Support' => sub {
|
||||||
|
requires 'Minion::Backend::SQLite';
|
||||||
|
};
|
||||||
|
|
||||||
feature 'codepoint-open', 'Code Point Open manipulation' => sub {
|
feature 'codepoint-open', 'Code Point Open manipulation' => sub {
|
||||||
requires 'Geo::UK::Postcode::CodePointOpen';
|
requires 'Geo::UK::Postcode::CodePointOpen';
|
||||||
};
|
};
|
||||||
|
|
|
@ -49,6 +49,7 @@ sub startup {
|
||||||
$self->plugin('Pear::LocalLoop::Plugin::Currency');
|
$self->plugin('Pear::LocalLoop::Plugin::Currency');
|
||||||
$self->plugin('Pear::LocalLoop::Plugin::Postcodes');
|
$self->plugin('Pear::LocalLoop::Plugin::Postcodes');
|
||||||
$self->plugin('Pear::LocalLoop::Plugin::TemplateHelpers');
|
$self->plugin('Pear::LocalLoop::Plugin::TemplateHelpers');
|
||||||
|
$self->plugin('Pear::LocalLoop::Plugin::Minion');
|
||||||
|
|
||||||
$self->plugin('Authentication' => {
|
$self->plugin('Authentication' => {
|
||||||
'load_user' => sub {
|
'load_user' => sub {
|
||||||
|
@ -196,6 +197,12 @@ sub startup {
|
||||||
|
|
||||||
my $admin_routes = $r->under('/admin')->to('admin#under');
|
my $admin_routes = $r->under('/admin')->to('admin#under');
|
||||||
|
|
||||||
|
if ( defined $config->{minion} ) {
|
||||||
|
$self->plugin( 'Minion::Admin' => {
|
||||||
|
return_to => '/admin/home',
|
||||||
|
route => $admin_routes->any('/minion'),
|
||||||
|
} );
|
||||||
|
}
|
||||||
$admin_routes->get('/home')->to('admin#home');
|
$admin_routes->get('/home')->to('admin#home');
|
||||||
|
|
||||||
$admin_routes->get('/tokens')->to('admin-tokens#index');
|
$admin_routes->get('/tokens')->to('admin-tokens#index');
|
||||||
|
|
38
lib/Pear/LocalLoop/Plugin/Minion.pm
Normal file
38
lib/Pear/LocalLoop/Plugin/Minion.pm
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
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 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 );
|
||||||
|
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;
|
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;
|
13
lib/Pear/LocalLoop/Plugin/Minion/Job/test.pm
Normal file
13
lib/Pear/LocalLoop/Plugin/Minion/Job/test.pm
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package Pear::LocalLoop::Plugin::Minion::Job::test;
|
||||||
|
use Mojo::Base 'Pear::LocalLoop::Plugin::Minion::Job';
|
||||||
|
|
||||||
|
sub run {
|
||||||
|
my ( $self, @args ) = @_;
|
||||||
|
|
||||||
|
$self->job->app->log->debug( 'Testing Job' );
|
||||||
|
for my $arg ( @args ) {
|
||||||
|
$self->job->app->log->debug( $arg );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
|
@ -3,4 +3,7 @@
|
||||||
user => undef,
|
user => undef,
|
||||||
pass => undef,
|
pass => undef,
|
||||||
key => "a",
|
key => "a",
|
||||||
|
minion => {
|
||||||
|
SQLite => 'sqlite:minion.db',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
Reference in a new issue