mojolicious / minion

:octopus: Perl high performance job queue

Home Page:https://metacpan.org/release/Minion

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make Minion easier to use outside of Mojolicious web apps

kraih opened this issue · comments

While installing Minion will always require Mojolicious, there is no real reason for the worker to be a web application. I believe all we need to do is move the worker lifecycle code from Minion::Command::minion::worker into a new module or Minion::Worker method. All the log messages could become events in Minion::Worker that Minion::Command::minion::worker subscribes to.

use Minion;

my $minion = Minion->new(Pg => 'postgres://...');
$minion->add_task(foo => sub {
  my ($job, @args) = @_;
  ...
});
$minion->add_task(bar => sub {
  my ($job, @args) = @_;
  ...
});

my $worker = $minion->worker;
$worker->{jobs} = 12;
$worker->run;

That would still leave the app attribute, but that's pretty easy to ignore because of it's default value, and doesn't really get in the way.