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