★★★ Доброго всем ★★★



0.9095 (up to Minion version/10+child minor)


Mojolicious::Plugin::Minion::Workers - does extend base Mojolicious::Plugin::Minion on manage Minion workers.


  # Mojolicious (define amount workers in config)
  $self->plugin('Minion::Workers' => {Pg => ..., workers=>2, manage=>1, });
  # or pass to $app->minion->workers->manage(<number>) for run later
  $self->plugin('Minion::Workers' => {Pg => ...});

  # Mojolicious::Lite (define amount workers in config)
  plugin 'Minion::Workers' => {Pg => ..., workers=>2};

  # Add tasks to your application
  app->minion->add_task(something_slow => sub {
    my ($job, @args) = @_;
  # But you can define tasks in config as well
  $self->plugin('Minion::Workers' => {Pg => ..., tasks => { foo_task => sub { ... }, }, });
  # Start manage with amount workers
  # or get number from config

  # Start jobs from anywhere in your application


Mojolicious::Plugin::Minion::Workers is a Mojolicious plugin for the Minion job queue and has extending base Mojolicious::Plugin::Minion for enable workers managment.

Extend base plugin config

Mojolicious::Plugin::Minion::Workers apply all config options of the base plugin Mojolicious::Plugin::Minion, and define following:

workers => <integer>

Amount of Minion workers need to start/restart. None defaults. This value can be overriden on $app->minion->workers->manage(...).

  ..., workers => 4, ...

manage => <boolean>

Start/restart Minion workers during plugin registration. Defaults to false. If this option is not set then you can start Minion workers by $app->minion->workers->manage() see below.

  ..., manage => 1, ...

tasks => <hashref>

You can define Minion tasks in config.

  ..., tasks => {foo_task => sub { ... }, ...},

<backend name: Pg|SQLite|...> => <connection string> | <backend object> | <coderef>

If config parameter backend name is a coderef then returned value (connection string or backend object) from callback will reassigned to backend name config option, i.e. $conf->{<backend name>} = $conf->{<backend name>}->($app);.

  ..., Pg => sub { my $app = shift; ... }, ...

Manage workers

Mojolicious::Plugin::Minion::Workers add attr workers to the $app->minion object. The $app->minion->workers object has following public methods.

manage(integer amount)

Start/restart Minion passed amount workers or get its from plugin config. None workers mean skip managment.


Tested manual on standard shell commands (on Linux) with Minion::Backend::Pg:

  $ perl script/ daemon         # one Minion worker will be starting
  $ perl script/ prefork        # your amount Minion workers will be starting
  $ morbo script/               # when morbo restarts on watch changes one Minion worker will be restarting too
  $ hypnotoad script/           # your amount Minion workers will be starting
  $ hypnotoad script/           # on hot deploy Minion workers will be restarting too
  $ hypnotoad -s script/        # Minion workers will stoping too

NOTE. For shell commands $ morbo script/ and $ perl script/ daemon amount Minion workers is one process always.

NOTE. In case with hypnotoad if you want $ kill -USR2 app_pid then Minion workers will not restarts, sorry. Always use hot deploy command $ hypnotoad script/ .

BIG NOTE. When Minion workers restarts (hypnotoad | morbo) then ALL exists Minion processes stopped and then running. So if you run many separate apps with one database backend then dont use this module or set separate backend databases as well.

NOTE. PSGI application did not tested.

NOTE. With Minion::Backend::SQLite Minion workers starting but jobs does not execute. An other backends even not tested.


Mojolicious::Plugin::Minion::Workers enable all helpers through base plugin Mojolicious::Plugin::Minion, thus you dont need apply base plugin (auto register).


Mojolicious::Plugin::Minion::Workers inherits all methods from Mojolicious::Plugin::Minion and override the following new ones.


  $plugin->register(Mojolicious->new, <config hashref>);

Register plugin in Mojolicious application.


Mojolicious::Plugin::Minion, Minion, Mojolicious::Guides,


Михаил Че (Mikhail Che), <mche[-at-]>


Please report any bugs or feature requests at Pull requests also welcome.


Copyright 2019+ Mikhail Che.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.