line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id$ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package TheSchwartz::Worker; |
4
|
18
|
|
|
18
|
|
1248120
|
use strict; |
|
18
|
|
|
|
|
51
|
|
|
18
|
|
|
|
|
667
|
|
5
|
|
|
|
|
|
|
|
6
|
18
|
|
|
18
|
|
101
|
use Carp qw( croak ); |
|
18
|
|
|
|
|
46
|
|
|
18
|
|
|
|
|
818
|
|
7
|
18
|
|
|
18
|
|
107
|
use Storable (); |
|
18
|
|
|
|
|
38
|
|
|
18
|
|
|
|
|
6802
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub grab_job { |
10
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
11
|
0
|
|
|
|
|
|
my ($client) = @_; |
12
|
0
|
|
|
|
|
|
return $client->find_job_for_workers( [$class] ); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
0
|
1
|
|
sub keep_exit_status_for {0} |
16
|
0
|
|
|
0
|
1
|
|
sub max_retries {0} |
17
|
0
|
|
|
0
|
1
|
|
sub retry_delay {0} |
18
|
0
|
|
|
0
|
1
|
|
sub grab_for { 60 * 60 } ## 1 hour |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub work_safely { |
21
|
0
|
|
|
0
|
1
|
|
my ( $class, $job ) = @_; |
22
|
0
|
|
|
|
|
|
my $client = $job->handle->client; |
23
|
0
|
|
|
|
|
|
my $res; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
$job->debug("Working on $class ..."); |
26
|
0
|
|
|
|
|
|
$job->set_as_current; |
27
|
0
|
|
|
|
|
|
$client->start_scoreboard; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
eval { $res = $class->work($job); }; |
|
0
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $errstr = $@; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $cjob = $client->current_job; |
33
|
0
|
0
|
|
|
|
|
if ($errstr) { |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# something went wrong, better make a rollback! |
36
|
0
|
|
|
|
|
|
my $driver = $cjob->driver; |
37
|
0
|
|
|
|
|
|
$driver->rollback; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
$job->debug("Eval failure: $errstr"); |
40
|
0
|
|
|
|
|
|
$cjob->failed($errstr); |
41
|
|
|
|
|
|
|
} |
42
|
0
|
0
|
0
|
|
|
|
if ( !$cjob->was_declined && !$cjob->did_something ) { |
43
|
0
|
|
|
|
|
|
$cjob->failed( |
44
|
|
|
|
|
|
|
'Job did not explicitly complete, fail, or get replaced'); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$client->end_scoreboard; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# FIXME: this return value is kinda useless/undefined. should we even return anything? any callers? -brad |
50
|
0
|
|
|
|
|
|
return $res; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |