line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gearman::Driver::Console::Basic; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2078
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use DateTime; |
5
|
|
|
|
|
|
|
use Time::HiRes; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Gearman::Driver::Console::Basic - Provides basic console commands |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 DESCRIPTION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
This implements the basic management console commands like C<status>, |
14
|
|
|
|
|
|
|
C<quit>, C<shutdown>, ... |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 COMMANDS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head2 status |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Parameters: C<none> |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
status |
23
|
|
|
|
|
|
|
GDExamples::Convert::convert_to_jpeg 0 5 0 2010-01-29T20:37:17 1970-01-01T00:00:00 |
24
|
|
|
|
|
|
|
GDExamples::Convert::convert_to_gif 0 5 0 2010-01-29T20:37:12 2010-01-29T20:37:12 some error |
25
|
|
|
|
|
|
|
. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Columns are separated by at least two spaces in this order: |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=over 4 |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=item * job_name |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=item * min_processes |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item * max_processes |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=item * current_processes |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item * last_run |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item * last_error |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item * last_error_message |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=back |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub status { |
50
|
|
|
|
|
|
|
my ($self) = @_; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# get maximum lengths |
53
|
|
|
|
|
|
|
my @max = ( 0, 1, 1, 1, 1, 1, 1 ); |
54
|
|
|
|
|
|
|
foreach my $job ( $self->driver->get_jobs ) { |
55
|
|
|
|
|
|
|
my $lasterror_msg = $job->lasterror_msg; |
56
|
|
|
|
|
|
|
$max[0] = length $job->name if $max[0] < length $job->name; |
57
|
|
|
|
|
|
|
$max[1] = length $job->min_processes if $max[1] < length $job->min_processes; |
58
|
|
|
|
|
|
|
$max[2] = length $job->max_processes if $max[2] < length $job->max_processes; |
59
|
|
|
|
|
|
|
$max[3] = length $job->count_processes if $max[3] < length $job->count_processes; |
60
|
|
|
|
|
|
|
$max[4] = length $job->lastrun if $max[4] < length $job->lastrun; |
61
|
|
|
|
|
|
|
$max[5] = length $job->lasterror if $max[5] < length $job->lasterror; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my @result = (); |
65
|
|
|
|
|
|
|
foreach my $job ( $self->driver->get_jobs ) { |
66
|
|
|
|
|
|
|
my $lasterror_msg = $job->lasterror_msg; |
67
|
|
|
|
|
|
|
chomp $lasterror_msg; |
68
|
|
|
|
|
|
|
push @result, |
69
|
|
|
|
|
|
|
sprintf( |
70
|
|
|
|
|
|
|
"%-$max[0]s %$max[1]d %$max[2]d %$max[3]d %$max[4]s %$max[5]s %s", |
71
|
|
|
|
|
|
|
$job->name, $job->min_processes, $job->max_processes, $job->count_processes, |
72
|
|
|
|
|
|
|
DateTime->from_epoch( epoch => $job->lastrun ), |
73
|
|
|
|
|
|
|
DateTime->from_epoch( epoch => $job->lasterror ), |
74
|
|
|
|
|
|
|
$lasterror_msg ? "ERROR: $lasterror_msg" : "" |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
return @result; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 set_min_processes |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Parameters: C<job_name min_processes> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
set_min_processes asdf 5 |
86
|
|
|
|
|
|
|
ERR invalid_job_name: asdf |
87
|
|
|
|
|
|
|
set_min_processes GDExamples::Convert::convert_to_jpeg ten |
88
|
|
|
|
|
|
|
ERR invalid_value: min_processes must be >= 0 |
89
|
|
|
|
|
|
|
set_min_processes GDExamples::Convert::convert_to_jpeg 10 |
90
|
|
|
|
|
|
|
ERR invalid_value: min_processes must be smaller than max_processes |
91
|
|
|
|
|
|
|
set_min_processes GDExamples::Convert::convert_to_jpeg 5 |
92
|
|
|
|
|
|
|
OK |
93
|
|
|
|
|
|
|
. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub set_min_processes { |
98
|
|
|
|
|
|
|
my ( $self, $job_name, $min_processes ) = @_; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $job = $self->get_job($job_name); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
if ( !defined($min_processes) || $min_processes !~ /^\d+$/ || $min_processes < 0 ) { |
103
|
|
|
|
|
|
|
die "ERR invalid_value: min_processes must be >= 0\n"; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
if ( $min_processes > $job->max_processes ) { |
107
|
|
|
|
|
|
|
die "ERR invalid_value: min_processes must be smaller than max_processes\n"; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
$job->min_processes($min_processes); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
return "OK"; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 set_max_processes |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Parameters: C<job_name max_processes> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
set_max_processes asdf 5 |
120
|
|
|
|
|
|
|
ERR invalid_job_name: asdf |
121
|
|
|
|
|
|
|
set_max_processes GDExamples::Convert::convert_to_jpeg ten |
122
|
|
|
|
|
|
|
ERR invalid_value: max_processes must be >= 0 |
123
|
|
|
|
|
|
|
set_max_processes GDExamples::Convert::convert_to_jpeg 0 |
124
|
|
|
|
|
|
|
ERR invalid_value: max_processes must be greater than min_processes |
125
|
|
|
|
|
|
|
set_max_processes GDExamples::Convert::convert_to_jpeg 6 |
126
|
|
|
|
|
|
|
OK |
127
|
|
|
|
|
|
|
. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub set_max_processes { |
132
|
|
|
|
|
|
|
my ( $self, $job_name, $max_processes ) = @_; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my $job = $self->get_job($job_name); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
if ( !defined($max_processes) || $max_processes !~ /^\d+$/ || $max_processes < 0 ) { |
137
|
|
|
|
|
|
|
die "ERR invalid_value: max_processes must be >= 0\n"; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
if ( $max_processes < $job->min_processes ) { |
141
|
|
|
|
|
|
|
die "ERR invalid_value: max_processes must be greater than min_processes\n"; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
$job->max_processes($max_processes); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
return "OK"; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 set_processes |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Parameters: C<job_name min_processes max_processes> |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
set_processes asdf 1 1 |
154
|
|
|
|
|
|
|
ERR invalid_job_name: asdf |
155
|
|
|
|
|
|
|
set_processes GDExamples::Convert::convert_to_jpeg ten ten |
156
|
|
|
|
|
|
|
ERR invalid_value: min_processes must be >= 0 |
157
|
|
|
|
|
|
|
set_processes GDExamples::Convert::convert_to_jpeg 1 ten |
158
|
|
|
|
|
|
|
ERR invalid_value: max_processes must be >= 0 |
159
|
|
|
|
|
|
|
set_processes GDExamples::Convert::convert_to_jpeg 5 1 |
160
|
|
|
|
|
|
|
ERR invalid_value: max_processes must be greater than min_processes |
161
|
|
|
|
|
|
|
set_processes GDExamples::Convert::convert_to_jpeg 1 5 |
162
|
|
|
|
|
|
|
OK |
163
|
|
|
|
|
|
|
. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub set_processes { |
168
|
|
|
|
|
|
|
my ( $self, $job_name, $min_processes, $max_processes ) = @_; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
my $job = $self->get_job($job_name); |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
if ( !defined($min_processes) || $min_processes !~ /^\d+$/ || $min_processes < 0 ) { |
173
|
|
|
|
|
|
|
die "ERR invalid_value: min_processes must be >= 0\n"; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
if ( !defined($max_processes) || $max_processes !~ /^\d+$/ || $max_processes < 0 ) { |
177
|
|
|
|
|
|
|
die "ERR invalid_value: max_processes must be >= 0\n"; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
if ( $max_processes < $min_processes ) { |
181
|
|
|
|
|
|
|
die "ERR invalid_value: max_processes must be greater than min_processes\n"; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
$job->min_processes($min_processes); |
185
|
|
|
|
|
|
|
$job->max_processes($max_processes); |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
return "OK"; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 show |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Parameters: C<job_name> |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
show GDExamples::Convert::convert_to_jpeg |
195
|
|
|
|
|
|
|
GDExamples::Convert::convert_to_jpeg 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 |
196
|
|
|
|
|
|
|
3662 |
197
|
|
|
|
|
|
|
3664 |
198
|
|
|
|
|
|
|
3663 |
199
|
|
|
|
|
|
|
. |
200
|
|
|
|
|
|
|
show GDExamples::Convert::convert_to_gif |
201
|
|
|
|
|
|
|
GDExamples::Convert::convert_to_gif 0 5 0 1970-01-01T00:00:00 1970-01-01T00:00:00 |
202
|
|
|
|
|
|
|
3665 |
203
|
|
|
|
|
|
|
. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=cut |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub show { |
208
|
|
|
|
|
|
|
my ( $self, $job_name ) = @_; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
my $job = $self->get_job($job_name); |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
my @result = (); |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
my $lasterror_msg = $job->lasterror_msg; |
215
|
|
|
|
|
|
|
chomp $lasterror_msg; |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
push @result, |
218
|
|
|
|
|
|
|
sprintf( |
219
|
|
|
|
|
|
|
"%s %d %d %d %s %s %s", |
220
|
|
|
|
|
|
|
$job->name, $job->min_processes, $job->max_processes, $job->count_processes, |
221
|
|
|
|
|
|
|
DateTime->from_epoch( epoch => $job->lastrun ), |
222
|
|
|
|
|
|
|
DateTime->from_epoch( epoch => $job->lasterror ), |
223
|
|
|
|
|
|
|
$lasterror_msg ? "ERROR: $lasterror_msg" : "" |
224
|
|
|
|
|
|
|
); |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
push @result, $job->get_pids; |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
return @result; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head2 kill |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Parameters: C<pid> [<pid> <pid> ...] |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
kill 1 |
236
|
|
|
|
|
|
|
ERR invalid_value: the given PID(s) do not belong to us |
237
|
|
|
|
|
|
|
kill 3662 |
238
|
|
|
|
|
|
|
OK |
239
|
|
|
|
|
|
|
. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=cut |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub kill { |
244
|
|
|
|
|
|
|
my ( $self, @pids ) = @_; |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
my @valid_pids = (); |
247
|
|
|
|
|
|
|
foreach my $job ( $self->driver->get_jobs ) { |
248
|
|
|
|
|
|
|
my @job_pids = $job->get_pids; |
249
|
|
|
|
|
|
|
foreach my $pid (@pids) { |
250
|
|
|
|
|
|
|
if ( grep $_ eq $pid, @job_pids ) { |
251
|
|
|
|
|
|
|
push @valid_pids, $pid; |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
die "ERR invalid_value: the given PID(s) do not belong to us\n" unless @valid_pids; |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
CORE::kill 15, @valid_pids; |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
return "OK"; |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head2 killall |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
Kills all childs/pids of given job. |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Parameters: C<job_name> [<job_name> <job_name> ...] |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
killall GDExamples::Convert::convert_to_jpeg |
270
|
|
|
|
|
|
|
OK |
271
|
|
|
|
|
|
|
. |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
It also accepts C<*> as parameter to kill all jobs, so be careful |
274
|
|
|
|
|
|
|
with that! |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=cut |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
sub killall { |
279
|
|
|
|
|
|
|
my ( $self, @job_names ) = @_; |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
die "ERR invalid_value: no job_names given\n" unless scalar(@job_names); |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
my $kill = sub { |
284
|
|
|
|
|
|
|
my ($job) = @_; |
285
|
|
|
|
|
|
|
my @pids = $job->get_pids; |
286
|
|
|
|
|
|
|
CORE::kill 15, @pids; |
287
|
|
|
|
|
|
|
Time::HiRes::usleep(50); # prevent POE from freaking out |
288
|
|
|
|
|
|
|
}; |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
if ( defined $job_names[0] && $job_names[0] eq '*' && scalar(@job_names) == 1 ) { |
291
|
|
|
|
|
|
|
foreach my $job ( $self->driver->get_jobs ) { |
292
|
|
|
|
|
|
|
$kill->($job); |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
else { |
297
|
|
|
|
|
|
|
foreach my $job_name (@job_names) { |
298
|
|
|
|
|
|
|
my $job = $self->get_job($job_name); |
299
|
|
|
|
|
|
|
$kill->($job); |
300
|
|
|
|
|
|
|
} |
301
|
|
|
|
|
|
|
} |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
return "OK"; |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=head2 quit |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
Parameters: C<none> |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
Closes your connection gracefully. |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
=head2 shutdown |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
Parameters: C<none> |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
Shuts L<Gearman::Driver> down. |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
=cut |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
sub shutdown { |
321
|
|
|
|
|
|
|
my ($self) = @_; |
322
|
|
|
|
|
|
|
$self->driver->shutdown; |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=head1 AUTHOR |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
See L<Gearman::Driver>. |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
See L<Gearman::Driver>. |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
=head1 SEE ALSO |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
=over 4 |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
=item * L<Gearman::Driver> |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Adaptor> |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Console> |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Console::Client> |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Job> |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Job::Method> |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Loader> |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Observer> |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
=item * L<Gearman::Driver::Worker> |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
=back |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
=cut |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
no Moose::Role; |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
1; |