| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Minion::Command::minion::worker; |
|
2
|
1
|
|
|
1
|
|
25640
|
use Mojo::Base 'Mojolicious::Command'; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
271
|
use Mojo::Util qw(getopt); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
548
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has description => 'Start Minion worker'; |
|
7
|
|
|
|
|
|
|
has usage => sub { shift->extract_usage }; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub run { |
|
10
|
0
|
|
|
0
|
1
|
|
my ($self, @args) = @_; |
|
11
|
|
|
|
|
|
|
|
|
12
|
0
|
|
|
|
|
|
my $worker = $self->app->minion->worker; |
|
13
|
0
|
|
|
|
|
|
my $status = $worker->status; |
|
14
|
|
|
|
|
|
|
getopt \@args, |
|
15
|
|
|
|
|
|
|
'C|command-interval=i' => \$status->{command_interval}, |
|
16
|
|
|
|
|
|
|
'D|dequeue-timeout=i' => \$status->{dequeue_timeout}, |
|
17
|
|
|
|
|
|
|
'I|heartbeat-interval=i' => \$status->{heartbeat_interval}, |
|
18
|
|
|
|
|
|
|
'j|jobs=i' => \$status->{jobs}, |
|
19
|
|
|
|
|
|
|
'q|queue=s' => \my @queues, |
|
20
|
|
|
|
|
|
|
'R|repair-interval=i' => \$status->{repair_interval}, |
|
21
|
|
|
|
|
|
|
's|spare=i' => \$status->{spare}, |
|
22
|
0
|
|
|
|
|
|
'S|spare-min-priority=i' => \$status->{spare_min_priority}; |
|
23
|
0
|
0
|
|
|
|
|
$status->{queues} = \@queues if @queues; |
|
24
|
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $log = $self->app->log; |
|
26
|
0
|
|
|
|
|
|
$log->info("Worker $$ started"); |
|
27
|
0
|
|
|
0
|
|
|
$worker->on(dequeue => sub { pop->once(spawn => \&_spawn) }); |
|
|
0
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
$worker->run; |
|
29
|
0
|
|
|
|
|
|
$log->info("Worker $$ stopped"); |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _spawn { |
|
33
|
0
|
|
|
0
|
|
|
my ($job, $pid) = @_; |
|
34
|
0
|
|
|
|
|
|
my ($id, $task) = ($job->id, $job->task); |
|
35
|
0
|
|
|
|
|
|
$job->app->log->debug(qq{Process $pid is performing job "$id" with task "$task"}); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
1; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=encoding utf8 |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 NAME |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Minion::Command::minion::worker - Minion worker command |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Usage: APPLICATION minion worker [OPTIONS] |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
./myapp.pl minion worker |
|
51
|
|
|
|
|
|
|
./myapp.pl minion worker -m production -I 15 -C 5 -R 3600 -j 10 |
|
52
|
|
|
|
|
|
|
./myapp.pl minion worker -q important -q default |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Options: |
|
55
|
|
|
|
|
|
|
-C, --command-interval Worker remote control command interval, |
|
56
|
|
|
|
|
|
|
defaults to 10 |
|
57
|
|
|
|
|
|
|
-D, --dequeue-timeout Maximum amount of time to wait for |
|
58
|
|
|
|
|
|
|
jobs, defaults to 5 |
|
59
|
|
|
|
|
|
|
-h, --help Show this summary of available options |
|
60
|
|
|
|
|
|
|
--home Path to home directory of your |
|
61
|
|
|
|
|
|
|
application, defaults to the value of |
|
62
|
|
|
|
|
|
|
MOJO_HOME or auto-detection |
|
63
|
|
|
|
|
|
|
-I, --heartbeat-interval Heartbeat interval, defaults to 300 |
|
64
|
|
|
|
|
|
|
-j, --jobs Maximum number of jobs to perform |
|
65
|
|
|
|
|
|
|
parallel in forked worker processes |
|
66
|
|
|
|
|
|
|
(not including spare processes), |
|
67
|
|
|
|
|
|
|
defaults to 4 |
|
68
|
|
|
|
|
|
|
-m, --mode Operating mode for your application, |
|
69
|
|
|
|
|
|
|
defaults to the value of |
|
70
|
|
|
|
|
|
|
MOJO_MODE/PLACK_ENV or "development" |
|
71
|
|
|
|
|
|
|
-q, --queue One or more queues to get jobs from, |
|
72
|
|
|
|
|
|
|
defaults to "default" |
|
73
|
|
|
|
|
|
|
-R, --repair-interval Repair interval, up to half of this |
|
74
|
|
|
|
|
|
|
value can be subtracted randomly to |
|
75
|
|
|
|
|
|
|
make sure not all workers repair at the |
|
76
|
|
|
|
|
|
|
same time, defaults to 21600 (6 hours) |
|
77
|
|
|
|
|
|
|
-s, --spare Number of spare worker processes to |
|
78
|
|
|
|
|
|
|
reserve for high priority jobs, |
|
79
|
|
|
|
|
|
|
defaults to 1 |
|
80
|
|
|
|
|
|
|
-S, --spare-min-priority Minimum priority of jobs to use spare |
|
81
|
|
|
|
|
|
|
worker processes for, defaults to 1 |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
L starts a L worker. You can have as many workers as you like. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 WORKER SIGNALS |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
The L process can be controlled at runtime with the following signals. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 INT, TERM |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Stop gracefully after finishing the current jobs. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 QUIT |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Stop immediately without finishing the current jobs. |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 JOB SIGNALS |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
The job processes spawned by the L process can be controlled at runtime with the |
|
102
|
|
|
|
|
|
|
following signals. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 INT, TERM |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This signal starts out with the operating system default and allows for jobs to install a custom signal handler to stop |
|
107
|
|
|
|
|
|
|
gracefully. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 USR1, USR2 |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
These signals start out being ignored and allow for jobs to install custom signal handlers. |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 REMOTE CONTROL COMMANDS |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
The L process can be controlled at runtime through L, |
|
116
|
|
|
|
|
|
|
from anywhere in the network, by broadcasting the following remote control commands. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 jobs |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
$ ./myapp.pl minion job -b jobs -a '[10]' |
|
121
|
|
|
|
|
|
|
$ ./myapp.pl minion job -b jobs -a '[10]' 23 |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Instruct one or more workers to change the number of jobs to perform concurrently. Setting this value to C<0> will |
|
124
|
|
|
|
|
|
|
effectively pause the worker. That means all current jobs will be finished, but no new ones accepted, until the number |
|
125
|
|
|
|
|
|
|
is increased again. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 kill |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
$ ./myapp.pl minion job -b kill -a '["INT", 10025]' |
|
130
|
|
|
|
|
|
|
$ ./myapp.pl minion job -b kill -a '["INT", 10025]' 23 |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Instruct one or more workers to send a signal to a job that is currently being performed. This command will be ignored |
|
133
|
|
|
|
|
|
|
by workers that do not have a job matching the id. That means it is safe to broadcast this command to all workers. |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 stop |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
$ ./myapp.pl minion job -b stop -a '[10025]' |
|
138
|
|
|
|
|
|
|
$ ./myapp.pl minion job -b stop -a '[10025]' 23 |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Instruct one or more workers to stop a job that is currently being performed immediately. This command will be ignored |
|
141
|
|
|
|
|
|
|
by workers that do not have a job matching the id. That means it is safe to broadcast this command to all workers. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
L inherits all attributes from L and implements the following |
|
146
|
|
|
|
|
|
|
new ones. |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 description |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
my $description = $worker->description; |
|
151
|
|
|
|
|
|
|
$worker = $worker->description('Foo'); |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Short description of this command, used for the command list. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 usage |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
my $usage = $worker->usage; |
|
158
|
|
|
|
|
|
|
$worker = $worker->usage('Foo'); |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Usage information for this command, used for the help screen. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 METHODS |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
L inherits all methods from L and implements the following new |
|
165
|
|
|
|
|
|
|
ones. |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 run |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
$worker->run(@ARGV); |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Run this command. |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
L, L, L, L, L. |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=cut |