Minion

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


8.10  2018-02-18
  - Improved Mojolicious::Plugin::Minion::Admin to use less distracting colors.
  - Fixed a bug in Mojolicious::Plugin::Minion::Admin where job results containing very long strings could not be
    displayed properly.

8.09  2018-01-25
  - Converted Mojolicious::Plugin::Minion::Admin to Bootstrap 4.

8.08  2017-12-15
  - Added busy and wait events to Minion::Worker.
  - Added dequeue_timeout option to run method in Minion::Worker.
  - Added -D option to worker command.

8.07  2017-12-11
  - Fixed guard method in Minion not to release already expired locks.

8.06  2017-12-11
  - Added active_locks field to stats methods in Minion, Minion::Backend and Minion::Backend::Pg again.
  - Improved Mojolicious::Plugin::Minion::Admin with support for locks.

lib/Minion/Worker.pm  view on Meta::CPAN

  $job = $minion->class_for_task($job->{task})
    ->new(args => $job->{args}, id => $job->{id}, minion => $minion, retries => $job->{retries}, task => $job->{task});
  $self->emit(dequeue => $job);
  return $job;
}

sub info { $_[0]->minion->backend->list_workers(0, 1, {ids => [$_[0]->id]})->{workers}[0] }

sub new {
  my $self = shift->SUPER::new(@_);
  $self->on(busy => sub { sleep 1 });
  return $self;
}

sub process_commands {
  my $self = shift;

  for my $command (@{$self->minion->backend->receive($self->id)}) {
    next unless my $cb = $self->commands->{shift @$command};
    $self->$cb(@$command);
  }

lib/Minion/Worker.pm  view on Meta::CPAN

    $self->minion->repair;
    $self->{last_repair} = steady_time;
  }

  # Check if jobs are finished
  my $jobs = $self->{jobs} ||= [];
  @$jobs = map { $_->is_finished && ++$status->{performed} ? () : $_ } @$jobs;

  # Job limit has been reached or worker is stopping
  my @extra;
  if    ($self->{finished} || ($status->{jobs} + $status->{spare}) <= @$jobs) { return $self->emit('busy') }
  elsif ($status->{jobs} <= @$jobs) { @extra = (min_priority => $status->{spare_min_priority}) }

  # Try to get more jobs
  my ($max, $queues) = @{$status}{qw(dequeue_timeout queues)};
  my $job = $self->emit('wait')->dequeue($max => {queues => $queues, @extra});
  push @$jobs, $job->start if $job;
}

1;

lib/Minion/Worker.pm  view on Meta::CPAN

gracefully.

=head2 USR1, USR2

These signals start out being ignored and allow for jobs to install custom signal handlers.

=head1 EVENTS

L<Minion::Worker> inherits all events from L<Mojo::EventEmitter> and can emit the following new ones.

=head2 busy

  $worker->on(busy => sub ($worker) {
    ...
  });

Emitted in the worker process when it is performing the maximum number of jobs in parallel.

  $worker->on(busy => sub ($worker) {
    my $max = $worker->status->{jobs};
    say "Performing $max jobs.";
  });

=head2 dequeue

  $worker->on(dequeue => sub ($worker, $job) {
    ...
  });

lib/Minion/Worker.pm  view on Meta::CPAN

Hash reference with whatever status information the worker would like to share.

=back

=head2 new

  my $worker = Minion::Worker->new;
  my $worker = Minion::Worker->new(status => {foo => 'bar'});
  my $worker = Minion::Worker->new({status => {foo => 'bar'}});

Construct a new L<Minion::Worker> object and subscribe to L</"busy"> event with default handler that sleeps for one
second.

=head2 process_commands

  $worker = $worker->process_commands;

Process worker remote control commands.

=head2 register

lib/Mojolicious/Plugin/Minion/resources/templates/minion/workers.html.ep  view on Meta::CPAN

                <a href="<%= url_for->query({id => $worker->{id}}) %>">
                  <%= $worker->{id} %>
                </a>
              </td>
              <td><%= $worker->{host} %></td>
              <td><%= $worker->{pid} %></td>
              <td class="from-now"><%= $worker->{started} %></td>
              <td><%= $related->($worker) %></td>
              <td class="accordion-toggle collapsed" data-toggle="collapse" data-target="#worker<%= $i %>">
                % if (@{$worker->{jobs}}) {
                  <span class="badge badge-primary">busy</span>
                % }
                % else {
                  <span class="badge badge-secondary">idle</span>
                % }
              </td>
              <td class="accordion-toggle collapsed expand" data-toggle="collapse" data-target="#worker<%= $i %>">
                <span class="fas fa-lg expand-icon"></span>
              </td>
            </tr>
            <tr>



( run in 0.239 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )