Molicious and Minion help request

33 views
Skip to first unread message

Árpád Hajdú

unread,
Jun 2, 2017, 12:09:15 PM6/2/17
to Mojolicious
Hello,

I need some help about the interaction when Mojolicious and Minion working together.

I have the full Mojolicious code where I load the Minion as a plugin and using Pg as a backend. 

sub status {
        my $c = shift;
        $c->render(json =>  $c->app->minion->stats, status => 200 );
        return;
}

This is showing me the following output when the worker is not running:
{"active_jobs":0,"active_workers":0,"delayed_jobs":0,"enqueued_jobs":43,"failed_jobs":0,"finished_jobs":0,"inactive_jobs":7,"inactive_workers":0}

After I start the minion worker in a different terminal on the same host and code:
{"active_jobs":0,"active_workers":0,"delayed_jobs":0,"enqueued_jobs":43,"failed_jobs":0,"finished_jobs":0,"inactive_jobs":7,"inactive_workers":1}

Inactive worker number increases as expected. 

I am planning to use the following endpoint to post a costly long running background job:

sub rescan {
my $c = shift;
my $minion = $c->app->minion;
$minion->add_task( 'rescan' => sub{
my $job = shift;
$job->app->SCSICleanup($job);
});
$minion->enqueue('rescan');
$c->render(json => {Service => 'Rescan'}, status => 200 );
return;
}

After I called the rescan function I have the following job in the database: (select * from minion_jobs order by id desc limit 1 ;)
44;"[]";"2017-06-02 16:58:52.252232+01";"2017-06-02 16:58:52.252232+01";"";0;"";"";0;"";"inactive";"rescan";;"default";1;"{}"

The job remain inactive even if the worker is running.
In the development.log I have the following - worker restarted after code changes:
[Fri Jun  2 17:04:09 2017] [debug] Loading Plugin Helpers
[Fri Jun  2 17:04:09 2017] [debug] Loading Plugin Database
[Fri Jun  2 17:04:09 2017] [debug] Initialise database connection
[Fri Jun  2 17:04:09 2017] [debug] Database Version: PostgreSQL 9.5.7 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 5.4.0-6ubuntu
1~16.04.4) 5.4.0 20160609, 64-bit
[Fri Jun  2 17:04:09 2017] [debug] Loading Plugin Minion
[Fri Jun  2 17:04:09 2017] [debug] Loading Plugin SCSI
[Fri Jun  2 17:04:09 2017] [debug] Loading Plugin Jobs
[Fri Jun  2 17:04:09 2017] [debug] Worker 4127 started
[Fri Jun  2 17:04:09 2017] [debug] Checking worker registry and job queue


I tried the following modification:
sub rescan {
my $c = shift;
my $minion = $c->app->minion;
$minion->add_task( 'rescan' => sub{
my $job = shift;
$job->app->SCSICleanup($job);
});
my id = $minion->enqueue('rescan');
$minion->job($id)->start;
$c->render(json => {Service => 'Rescan'}, status => 200 );
return;
}

After the modification the situation is exactly the same:
45;"[]";"2017-06-02 17:04:12.067348+01";"2017-06-02 17:04:12.067348+01";"";0;"";"";0;"";"inactive";"rescan";;"default";1;"{}"

Could you please help me what I am doing wrong or what I missed ? 

Regards,
Arpad

Sebastian Riedel

unread,
Jun 2, 2017, 3:03:42 PM6/2/17
to mojol...@googlegroups.com
> Could you please help me what I am doing wrong or what I missed ?

Add your task during application startup.

--
Sebastian Riedel
http://mojolicio.us
http://github.com/kraih
http://twitter.com/kraih

Sebastian Riedel

unread,
Jun 2, 2017, 3:05:23 PM6/2/17
to mojol...@googlegroups.com
Actually, it might be best if you start experimenting with the example
from the Minion documentation.

Árpád Hajdú

unread,
Jun 3, 2017, 4:59:09 AM6/3/17
to Mojolicious
By adding the tasks in startup solved my issue ... Thanks.

I won't say the example is useful. It is a performance comparison only. It is not a real example.

sri

unread,
Jun 3, 2017, 8:36:22 AM6/3/17
to Mojolicious
I won't say the example is useful. It is a performance comparison only. It is not a real example.

I have no idea what you're talking about, how is this not a real example?


--
sebastian 
Reply all
Reply to author
Forward
0 new messages