/usr/share/perl5/Minion/Worker.pm is in libminion-perl 6.02-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | package Minion::Worker;
use Mojo::Base 'Mojo::EventEmitter';
has commands => sub { {} };
has [qw(id minion)];
sub add_command { $_[0]->commands->{$_[1]} = $_[2] and return $_[0] }
sub dequeue {
my ($self, $wait, $options) = @_;
# Worker not registered
return undef unless my $id = $self->id;
my $minion = $self->minion;
return undef unless my $job = $minion->backend->dequeue($id, $wait, $options);
$job = Minion::Job->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->worker_info($_[0]->id) }
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);
}
return $self;
}
sub register { $_[0]->id($_[0]->minion->backend->register_worker($_[0]->id)) }
sub unregister {
my $self = shift;
$self->minion->backend->unregister_worker(delete $self->{id});
return $self;
}
1;
=encoding utf8
=head1 NAME
Minion::Worker - Minion worker
=head1 SYNOPSIS
use Minion::Worker;
my $worker = Minion::Worker->new(minion => $minion);
=head1 DESCRIPTION
L<Minion::Worker> performs jobs for L<Minion>.
=head1 EVENTS
L<Minion::Worker> inherits all events from L<Mojo::EventEmitter> and can emit
the following new ones.
=head2 dequeue
$worker->on(dequeue => sub {
my ($worker, $job) = @_;
...
});
Emitted in the worker process after a job has been dequeued.
$worker->on(dequeue => sub {
my ($worker, $job) = @_;
my $id = $job->id;
say "Job $id has been dequeued.";
});
=head1 ATTRIBUTES
L<Minion::Worker> implements the following attributes.
=head2 commands
my $commands = $worker->commands;
$worker = $worker->commands({jobs => sub {...}});
Registered worker remote control commands.
=head2 id
my $id = $worker->id;
$worker = $worker->id($id);
Worker id.
=head2 minion
my $minion = $worker->minion;
$worker = $worker->minion(Minion->new);
L<Minion> object this worker belongs to.
=head1 METHODS
L<Minion::Worker> inherits all methods from L<Mojo::EventEmitter> and
implements the following new ones.
=head2 add_command
$worker = $worker->add_command(jobs => sub {...});
Register a worker remote control command.
$worker->add_command(foo => sub {
my ($worker, @args) = @_;
...
});
=head2 dequeue
my $job = $worker->dequeue(0.5);
my $job = $worker->dequeue(0.5 => {queues => ['important']});
Wait a given amount of time in seconds for a job, dequeue L<Minion::Job> object
and transition from C<inactive> to C<active> state, or return C<undef> if queues
were empty.
These options are currently available:
=over 2
=item queues
queues => ['important']
One or more queues to dequeue jobs from, defaults to C<default>.
=back
=head2 info
my $info = $worker->info;
Get worker information.
# Check worker host
my $host = $worker->info->{host};
These fields are currently available:
=over 2
=item host
host => 'localhost'
Worker host.
=item jobs
jobs => ['10023', '10024', '10025', '10029']
Ids of jobs the worker is currently processing.
=item notified
notified => 784111777
Epoch time worker sent the last heartbeat.
=item pid
pid => 12345
Process id of worker.
=item started
started => 784111777
Epoch time worker was started.
=back
=head2 process_commands
$worker = $worker->process_commands;
Process worker remote control commands.
=head2 register
$worker = $worker->register;
Register worker or send heartbeat to show that this worker is still alive.
=head2 unregister
$worker = $worker->unregister;
Unregister worker.
=head1 SEE ALSO
L<Minion>, L<Mojolicious::Guides>, L<http://mojolicious.org>.
=cut
|