1

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.

Sachin Dangol
  • 504
  • 5
  • 13
  • 1
    The documentation only suggests that the _command_ becomes available, but I think you're still supposed to start the worker yourself. Most likely the worker stops after some time when there is no more work to be done, but you should look into its log for that – Corion Dec 14 '18 at 07:14
  • Thanks @Corion. I got confused by documentation as the minion command is available even when hypnotoad is not running. I mean `/var/www/apps/script/apps minion worker -m production` still runs fine when app is not run. I am not sure if there is log for minion. However, looks like log for hypnotoad suggests that workers were stopped gracefully after sometime: – Sachin Dangol Dec 14 '18 at 08:10
  • example worker being stopped: `[Fri Dec 14 13:59:24 2018] [info] Stopping worker 9716 gracefully (120 seconds)` – Sachin Dangol Dec 14 '18 at 08:23
  • 1
    The hypnotoad log is referring to Mojolicious workers. Minion workers are separate unrelated processes, that you must start and manage on their own. – Grinnz Dec 15 '18 at 05:11
  • Thank you. I thought there might be some way to manage Minion automatically. – Sachin Dangol Dec 15 '18 at 17:30

2 Answers2

4

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

Sachin Dangol
  • 504
  • 5
  • 13
0

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.

simone
  • 4,667
  • 4
  • 25
  • 47