| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Kevin::Command::kevin::worker; |
|
2
|
|
|
|
|
|
|
$Kevin::Command::kevin::worker::VERSION = '0.7.1'; |
|
3
|
|
|
|
|
|
|
# ABSTRACT: Alternative Minion worker command |
|
4
|
2
|
|
|
2
|
|
1114
|
use Mojo::Base 'Mojolicious::Command'; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
37450
|
use Minion::Worker; |
|
|
2
|
|
|
|
|
2760
|
|
|
|
2
|
|
|
|
|
13
|
|
|
7
|
2
|
|
|
2
|
|
58
|
use Mojo::Util 'getopt'; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
604
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has description => 'Start alternative Minion worker'; |
|
10
|
|
|
|
|
|
|
has usage => sub { shift->extract_usage }; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _worker { |
|
13
|
0
|
|
|
0
|
|
|
my $minion = shift; |
|
14
|
0
|
0
|
|
|
|
|
return $minion->kevin_worker(@_) if $minion->can('kevin_worker'); |
|
15
|
0
|
|
|
|
|
|
my $worker = Minion::Worker->with_roles('+Kevin')->new(minion => $minion, @_); |
|
16
|
0
|
|
|
|
|
|
$minion->emit(worker => $worker); |
|
17
|
0
|
|
|
|
|
|
return $worker; |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub run { |
|
21
|
0
|
|
|
0
|
1
|
|
my ($self, @args) = @_; |
|
22
|
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
my $defaults = {}; |
|
24
|
|
|
|
|
|
|
getopt \@args, |
|
25
|
|
|
|
|
|
|
'C|command-interval=i' => \$defaults->{command_interval}, |
|
26
|
|
|
|
|
|
|
'D|dequeue-timeout=i' => \$defaults->{dequeue_timeout}, |
|
27
|
|
|
|
|
|
|
'f|fast-start' => \$defaults->{fast_start}, |
|
28
|
|
|
|
|
|
|
'I|heartbeat-interval=i' => \$defaults->{heartbeat_interval}, |
|
29
|
|
|
|
|
|
|
'j|jobs=i' => \$defaults->{jobs}, |
|
30
|
|
|
|
|
|
|
'q|queue=s@' => \$defaults->{queues}, |
|
31
|
0
|
|
|
|
|
|
'R|repair-interval=i' => \$defaults->{repair_interval}; |
|
32
|
0
|
0
|
|
|
|
|
for (keys %$defaults) { delete $defaults->{$_} unless defined $defaults->{$_} } |
|
|
0
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $app = $self->app; |
|
35
|
0
|
|
|
|
|
|
my $worker = _worker($app->minion, defaults => $defaults, log => $app->log); |
|
36
|
0
|
|
|
|
|
|
$worker->run; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
#pod =encoding utf8 |
|
42
|
|
|
|
|
|
|
#pod |
|
43
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
|
44
|
|
|
|
|
|
|
#pod |
|
45
|
|
|
|
|
|
|
#pod Usage: APPLICATION kevin worker [OPTIONS] |
|
46
|
|
|
|
|
|
|
#pod |
|
47
|
|
|
|
|
|
|
#pod ./myapp.pl kevin worker |
|
48
|
|
|
|
|
|
|
#pod ./myapp.pl kevin worker -f |
|
49
|
|
|
|
|
|
|
#pod ./myapp.pl kevin worker -m production -I 15 -C 5 -R 3600 -j 10 |
|
50
|
|
|
|
|
|
|
#pod ./myapp.pl kevin worker -q important -q default |
|
51
|
|
|
|
|
|
|
#pod |
|
52
|
|
|
|
|
|
|
#pod Options: |
|
53
|
|
|
|
|
|
|
#pod -C, --command-interval Worker remote control command interval, |
|
54
|
|
|
|
|
|
|
#pod defaults to 10 |
|
55
|
|
|
|
|
|
|
#pod -D, dequeue-timeout Maximum amount of time to wait for |
|
56
|
|
|
|
|
|
|
#pod jobs, defaults 5 |
|
57
|
|
|
|
|
|
|
#pod -f, --fast-start Start processing jobs as fast as |
|
58
|
|
|
|
|
|
|
#pod possible and skip repairing on startup |
|
59
|
|
|
|
|
|
|
#pod -h, --help Show this summary of available options |
|
60
|
|
|
|
|
|
|
#pod --home Path to home directory of your |
|
61
|
|
|
|
|
|
|
#pod application, defaults to the value of |
|
62
|
|
|
|
|
|
|
#pod MOJO_HOME or auto-detection |
|
63
|
|
|
|
|
|
|
#pod -I, --heartbeat-interval Heartbeat interval, defaults to 300 |
|
64
|
|
|
|
|
|
|
#pod -j, --jobs Maximum number of jobs to perform |
|
65
|
|
|
|
|
|
|
#pod parallel in forked worker processes, |
|
66
|
|
|
|
|
|
|
#pod defaults to 4 |
|
67
|
|
|
|
|
|
|
#pod -m, --mode Operating mode for your application, |
|
68
|
|
|
|
|
|
|
#pod defaults to the value of |
|
69
|
|
|
|
|
|
|
#pod MOJO_MODE/PLACK_ENV or "development" |
|
70
|
|
|
|
|
|
|
#pod -q, --queue One or more queues to get jobs from, |
|
71
|
|
|
|
|
|
|
#pod defaults to "default" |
|
72
|
|
|
|
|
|
|
#pod -R, --repair-interval Repair interval, up to half of this |
|
73
|
|
|
|
|
|
|
#pod value can be subtracted randomly to |
|
74
|
|
|
|
|
|
|
#pod make sure not all workers repair at the |
|
75
|
|
|
|
|
|
|
#pod same time, defaults to 21600 (6 hours) |
|
76
|
|
|
|
|
|
|
#pod |
|
77
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
|
78
|
|
|
|
|
|
|
#pod |
|
79
|
|
|
|
|
|
|
#pod L starts a L worker. You can have as |
|
80
|
|
|
|
|
|
|
#pod many workers as you like. |
|
81
|
|
|
|
|
|
|
#pod |
|
82
|
|
|
|
|
|
|
#pod This is a fork of L. The differences are: |
|
83
|
|
|
|
|
|
|
#pod |
|
84
|
|
|
|
|
|
|
#pod =over 4 |
|
85
|
|
|
|
|
|
|
#pod |
|
86
|
|
|
|
|
|
|
#pod =item * |
|
87
|
|
|
|
|
|
|
#pod |
|
88
|
|
|
|
|
|
|
#pod During immediate stops, the worker stops sending heartbeats, |
|
89
|
|
|
|
|
|
|
#pod processing remote commands and doing repairs. |
|
90
|
|
|
|
|
|
|
#pod |
|
91
|
|
|
|
|
|
|
#pod =item * |
|
92
|
|
|
|
|
|
|
#pod |
|
93
|
|
|
|
|
|
|
#pod During graceful stops, the worker stops doing repairs. |
|
94
|
|
|
|
|
|
|
#pod |
|
95
|
|
|
|
|
|
|
#pod =item * |
|
96
|
|
|
|
|
|
|
#pod |
|
97
|
|
|
|
|
|
|
#pod During a stop, when all jobs have finished, the worker |
|
98
|
|
|
|
|
|
|
#pod will quit promptly (without sleeping). |
|
99
|
|
|
|
|
|
|
#pod |
|
100
|
|
|
|
|
|
|
#pod =item * |
|
101
|
|
|
|
|
|
|
#pod |
|
102
|
|
|
|
|
|
|
#pod Allow to disable repairs with C<-R 0>. |
|
103
|
|
|
|
|
|
|
#pod |
|
104
|
|
|
|
|
|
|
#pod =back |
|
105
|
|
|
|
|
|
|
#pod |
|
106
|
|
|
|
|
|
|
#pod =head1 SIGNALS |
|
107
|
|
|
|
|
|
|
#pod |
|
108
|
|
|
|
|
|
|
#pod The L process can be controlled at runtime |
|
109
|
|
|
|
|
|
|
#pod with the following signals. |
|
110
|
|
|
|
|
|
|
#pod |
|
111
|
|
|
|
|
|
|
#pod =head2 INT, TERM |
|
112
|
|
|
|
|
|
|
#pod |
|
113
|
|
|
|
|
|
|
#pod Stop gracefully after finishing the current jobs. |
|
114
|
|
|
|
|
|
|
#pod |
|
115
|
|
|
|
|
|
|
#pod =head2 QUIT |
|
116
|
|
|
|
|
|
|
#pod |
|
117
|
|
|
|
|
|
|
#pod Stop immediately without finishing the current jobs. |
|
118
|
|
|
|
|
|
|
#pod |
|
119
|
|
|
|
|
|
|
#pod =head1 REMOTE CONTROL COMMANDS |
|
120
|
|
|
|
|
|
|
#pod |
|
121
|
|
|
|
|
|
|
#pod The L process can be controlled at runtime |
|
122
|
|
|
|
|
|
|
#pod through L, from anywhere in the network, by |
|
123
|
|
|
|
|
|
|
#pod broadcasting the following remote control commands. |
|
124
|
|
|
|
|
|
|
#pod |
|
125
|
|
|
|
|
|
|
#pod =head2 jobs |
|
126
|
|
|
|
|
|
|
#pod |
|
127
|
|
|
|
|
|
|
#pod $ ./myapp.pl minion job -b jobs -a '[10]' |
|
128
|
|
|
|
|
|
|
#pod $ ./myapp.pl minion job -b jobs -a '[10]' 23 |
|
129
|
|
|
|
|
|
|
#pod |
|
130
|
|
|
|
|
|
|
#pod Instruct one or more workers to change the number of jobs to perform |
|
131
|
|
|
|
|
|
|
#pod concurrently. Setting this value to C<0> will effectively pause the worker. That |
|
132
|
|
|
|
|
|
|
#pod means all current jobs will be finished, but no new ones accepted, until the |
|
133
|
|
|
|
|
|
|
#pod number is increased again. |
|
134
|
|
|
|
|
|
|
#pod |
|
135
|
|
|
|
|
|
|
#pod =head2 stop |
|
136
|
|
|
|
|
|
|
#pod |
|
137
|
|
|
|
|
|
|
#pod $ ./myapp.pl minion job -b stop -a '[10025]' |
|
138
|
|
|
|
|
|
|
#pod $ ./myapp.pl minion job -b stop -a '[10025]' 23 |
|
139
|
|
|
|
|
|
|
#pod |
|
140
|
|
|
|
|
|
|
#pod Instruct one or more workers to stop a job that is currently being performed |
|
141
|
|
|
|
|
|
|
#pod immediately. This command will be ignored by workers that do not have a job |
|
142
|
|
|
|
|
|
|
#pod matching the id. That means it is safe to broadcast this command to all workers. |
|
143
|
|
|
|
|
|
|
#pod |
|
144
|
|
|
|
|
|
|
#pod =head1 ATTRIBUTES |
|
145
|
|
|
|
|
|
|
#pod |
|
146
|
|
|
|
|
|
|
#pod L inherits all attributes from |
|
147
|
|
|
|
|
|
|
#pod L and implements the following new ones. |
|
148
|
|
|
|
|
|
|
#pod |
|
149
|
|
|
|
|
|
|
#pod =head2 description |
|
150
|
|
|
|
|
|
|
#pod |
|
151
|
|
|
|
|
|
|
#pod my $description = $worker->description; |
|
152
|
|
|
|
|
|
|
#pod $worker = $worker->description('Foo'); |
|
153
|
|
|
|
|
|
|
#pod |
|
154
|
|
|
|
|
|
|
#pod Short description of this command, used for the command list. |
|
155
|
|
|
|
|
|
|
#pod |
|
156
|
|
|
|
|
|
|
#pod =head2 usage |
|
157
|
|
|
|
|
|
|
#pod |
|
158
|
|
|
|
|
|
|
#pod my $usage = $worker->usage; |
|
159
|
|
|
|
|
|
|
#pod $worker = $worker->usage('Foo'); |
|
160
|
|
|
|
|
|
|
#pod |
|
161
|
|
|
|
|
|
|
#pod Usage information for this command, used for the help screen. |
|
162
|
|
|
|
|
|
|
#pod |
|
163
|
|
|
|
|
|
|
#pod =head1 METHODS |
|
164
|
|
|
|
|
|
|
#pod |
|
165
|
|
|
|
|
|
|
#pod L inherits all methods from |
|
166
|
|
|
|
|
|
|
#pod L and implements the following new ones. |
|
167
|
|
|
|
|
|
|
#pod |
|
168
|
|
|
|
|
|
|
#pod =head2 run |
|
169
|
|
|
|
|
|
|
#pod |
|
170
|
|
|
|
|
|
|
#pod $worker->run(@ARGV); |
|
171
|
|
|
|
|
|
|
#pod |
|
172
|
|
|
|
|
|
|
#pod Run this command. |
|
173
|
|
|
|
|
|
|
#pod |
|
174
|
|
|
|
|
|
|
#pod =head1 DEBUGGING |
|
175
|
|
|
|
|
|
|
#pod |
|
176
|
|
|
|
|
|
|
#pod You can set the C environment variable to have some |
|
177
|
|
|
|
|
|
|
#pod extra diagnostics information printed to C<< $app->log >>. |
|
178
|
|
|
|
|
|
|
#pod |
|
179
|
|
|
|
|
|
|
#pod KEVIN_WORKER_TRACE=1 |
|
180
|
|
|
|
|
|
|
#pod |
|
181
|
|
|
|
|
|
|
#pod =head1 SEE ALSO |
|
182
|
|
|
|
|
|
|
#pod |
|
183
|
|
|
|
|
|
|
#pod L, L, L. |
|
184
|
|
|
|
|
|
|
#pod |
|
185
|
|
|
|
|
|
|
#pod =cut |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
__END__ |