Mojolicious - minion worker doesn't start automatically

743 Views Asked by At

I am using Mojolicious full app and loading Minion (backend sqlite). My question is why minion worker doesn't start by itself when I start mojolicious app with hypnotoad. According to the documentation Minion it should:

Background worker processes are usually started with the command Minion::Command::minion::worker, which becomes automatically available when an application loads Mojolicious::Plugin::Minion.

Environment:

  • Red Hat Enterprise Linux Server - 7.5 (Maipo)
  • Perl v5.16.3
  • Mojolicious 8.0 (Supervillain)
  • Minion 9.01

Mojolicious full app

package Apps;

use Moo;
extends 'Mojolicious';

sub startup {
    my $self = shift;

    $self->plugin(Config => file => '/var/www/apps/lib/appconf.perl');
    $self->plugin(Minion => {SQLite => 'sqlite:/var/www/apps/db/minion_backend_sqlite.db'});
    ...
}

This is how I start my server:

/usr/local/bin/hypnotoad /var/www/apps/script/apps

Currently, I start minion worker in background( which also gets killed somehow after sometime, starangely) like this:

/var/www/apps/script/apps minion worker -m production

Thank you.

2

There are 2 best solutions below

0
On BEST ANSWER

As Corion and Grinnz mentioned in comments:

Minion workers are separate unrelated processes, that you must start and manage on your own.

Good news:

Mojolicious team has opened this issue. Will be solved soon: Allow for Minion worker to be started by the application server

0
On

Using Mojo::IOLoop::Subprocess you can start a subprocess within the app like this:

my $subprocess = Mojo::IOLoop::Subprocess->new;
$subprocess->run(sub {...}, sub{...})

Documentation here

That means that you can use the before_server_start hook to start worker subprocesses via app->minion->worker->run

Once they've started though there seems AFAIK no easy way to stop them when the app itself stops, so you have to check them and reap them - which is where Proc::ProcessTable can help.

I've put all this together in a quick and dirty plugin here.