<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">=encoding utf8

=head1 Mojolicious::Plugin::Minion::Workers

в…в…в… Р”РѕР±СЂРѕРіРѕ РІСЃРµРј в…в…в…

ВЎ ВЎ ВЎ ALL GLORY TO GLORIA ! ! !

=head1 VERSION

0.09077 (up to Minion 9.07/100+C&lt;minor&gt;)

=head1 NAME

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

=head1 SYNOPSIS

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

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

  # Add tasks to your application
  app-&gt;minion-&gt;add_task(something_slow =&gt; sub {
    my ($job, @args) = @_;
    sleep 5;
    say 'This is a background worker process.';
  });
  
  # But you can define tasks in config as well
  $self-&gt;plugin('Minion::Workers' =&gt; {Pg =&gt; ..., tasks =&gt; { foo_task =&gt; sub { ... }, }, });
  
  # Start manage with amount workers
  app-&gt;minion-&gt;workers-&gt;manage(4);
  # or get from config
  app-&gt;minion-&gt;workers-&gt;manage();

  # Start jobs from anywhere in your application

=head1 DESCRIPTION

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

=head1 Extend base plugin config

L&lt;Mojolicious::Plugin::Minion::Workers&gt; apply all config options of the base plugin L&lt;Mojolicious::Plugin::Minion&gt;,
and define following:

=head2 workers =&gt; &lt;integer&gt;

Amount of Minion workers need to start/restart. This value can be overriden on C&lt; $app-&gt;minion-&gt;workers-&gt;manage(...) &gt;.

  ..., workers =&gt; 4, ...

=head2 run =&gt; &lt;boolean&gt;

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

=head2 tasks = &gt; &lt;hashref&gt;

You can define Minion tasks in config.

  ..., tasks =&gt; {foo_task =&gt; sub { ... }, ...},

=head2 Pg =&gt; &lt;connection url&gt; | &lt;Mojo::Pg object&gt; | &lt;coderef&gt;

If config parameter B&lt;Pg&gt; is a B&lt;coderef&gt; then returned value of C&lt; $conf-&gt;{Pg} = $conf-&gt;{Pg}-&gt;($app); &gt; will assigned to Pg.

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

=head1 Manage workers

L&lt;Mojolicious::Plugin::Minion::Workers&gt; add attr B&lt;workers&gt; to the C&lt;&lt; $app-&gt;minion &gt;&gt; object.
C&lt;&lt; $app-&gt;minion-&gt;workers &gt;&gt; object has following public methods.

=head2 manage(integer amount)

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

  $app-&gt;minion-&gt;workers-&gt;manage(2);

Tested on standard shell commands (on Linux):

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

B&lt;NOTE&gt;. For shell commands C&lt; $ morbo script/app.pl &gt; and C&lt; $ perl script/app.pl daemon &gt;
amount workers always one process.

B&lt;NOTE&gt;. In case shell commands C &lt;$ hypnotoad script/app.pl &gt; and C&lt; $ kill -USR2 app_pid &gt; minion workers will not restarts, sorry.
Always use hot deploy command C&lt; $ hypnotoad script/app.pl &gt;.

B&lt;BIG NOTE&gt;. When minion workers restarts (hypnotoad | morbo) then B&lt;ALL&gt; exists minion processes stoped.
So if you run many separate apps with one database backend then dont use this module.
Or set separate backend databases as well.

=head1 HELPERS

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

=head1 METHODS

L&lt;Mojolicious::Plugin::Minion::Workers&gt; inherits all methods from
L&lt;Mojolicious::Plugin::Minion&gt; and override the following new ones.

=head2 register

  $plugin-&gt;register(Mojolicious-&gt;new, {Pg =&gt; ..., worker=&gt;1});

Register plugin in L&lt;Mojolicious&gt; application.

=head1 SEE ALSO

L&lt;Mojolicious::Plugin::Minion&gt;, L&lt;Minion&gt;, L&lt;Mojolicious::Guides&gt;, L&lt;https://mojolicious.org&gt;.

=head1 AUTHOR

РњРёС…Р°РёР» Р§Рµ (Mikhail Che), C&lt;&lt; &lt;mche[-at-]cpan.org&gt; &gt;&gt;

=head1 BUGS / CONTRIBUTING

Please report any bugs or feature requests at L&lt;https://github.com/mche/Mojolicious-Plugin-Minion-Workers/issues&gt;.
Pull requests also welcome.

=head1 COPYRIGHT

Copyright 2019+ Mikhail Che.

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


=cut
</pre></body></html>