Helios/TS/Job.pm

filter: Statementstmt 25.4% 13 / 51 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 57.1% 4 / 7 Podpod 100% 2 / 2 totaltotal 19.7% 19 / 96 CC 13 SCAR 33.5
CC
13
Cov
17%
set_exit_status
42.0
_failed
42.0
failed
12.0
CRAP 28.6
« Helios/ObjectDriver/DBI.pm ↑ Summary Helios/Logger/Internal.pm »
1 package Helios::TS::Job;
2  
3 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use base 'TheSchwartz::Job';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = "2.80";
9  
10 # FILE CHANGE HISTORY
11 # (This code is modified from the original TheSchwartz::Job.pm where noted.)
12 # [LH] [2013-10-04]: Virtual jobtypes: funcmap entries without actual
13 # TheSchwartz::Worker subclasses to back them up. Changed
14 # set_exit_status(), failed(), _failed() to use $job->{active_worker_class}
15 # instead of $job->funcname if $job->{active_worker_class} is set.
16  
17 0 ▶sub set_exit_status {
Subroutine set_exit_status: not called CC=6 SCAR=37.4
Pod documented
18 0 my $job = shift;
19 0 my($exit) = @_;
20 # [LH] [2013-10-04]: Use active_worker_class instead of funcname if AWC is set.
21 0 ▶ my $class = $job->{active_worker_class} || $job->funcname;
Condition0%0/3
$job->{'active_worker_class'} || $job->funcname
l!l&&r!l&&!r
000
MC/DC0%0/2
$job->{'active_worker_class'} || $job->funcname
$job->{'active_worker_class'} $job->funcname
Truth table0%0/3
A || B
A= $job->{'active_worker_class'}B= $job->funcname
ABresult
1X1
011
000
22 0 ▶ my $secs = $class->keep_exit_status_for or return;
Branch: 1 branch
BranchTrueFalseTotal
my $secs = $class->keep_exit_status_for or return 0 0 0
23 0 my $status = TheSchwartz::ExitStatus->new;
24 0 $status->jobid($job->jobid);
25 0 $status->funcid($job->funcid);
26 0 $status->completion_time(time);
27 0 $status->delete_after($status->completion_time + $secs);
28 0 $status->status($exit);
29  
30 0 my $driver = $job->driver;
31 0 $driver->insert($status);
32  
33 # and let's lazily clean some exitstatus while we're here. but
34 # rather than doing this query all the time, we do it 1/nth of the
35 # time, and deleting up to n*10 queries while we're at it.
36 # default n is 10% of the time, doing 100 deletes.
37 0 ▶ my $clean_thres = $TheSchwartz::T_EXITSTATUS_CLEAN_THRES || 0.10;
Condition0%0/2
$TheSchwartz::T_EXITSTATUS_CLEAN_THRES || 0.1
l!l
00
MC/DC0%0/1
$TheSchwartz::T_EXITSTATUS_CLEAN_THRES || 0.1
$TheSchwartz::T_EXITSTATUS_CLEAN_THRES
Truth table0%0/2
A
A= $TheSchwartz::T_EXITSTATUS_CLEAN_THRES
Aresult
11
00
38 0 ▶ if (rand() < $clean_thres) {
Branch: 1 branch
BranchTrueFalseTotal
if (rand() < $clean_thres) 0 0 0
39 0 my $unixtime = $driver->dbd->sql_for_unixtime;
40 0 ▶ $driver->remove('TheSchwartz::ExitStatus', {
Branch: 1 branch
BranchTrueFalseTotal
$driver->dbd->can_delete_with_limit ? : 0 0 0
41 delete_after => \ "< $unixtime",
42 }, {
43 nofetch => 1,
44 limit => $driver->dbd->can_delete_with_limit ? int(1 / $clean_thres * 100) : undef,
45 });
46 }
47  
48 0 return $status;
49 }
50  
51  
52 0 ▶sub failed {
Subroutine failed: not called CC=3 SCAR=24.8
Pod documented
53 0 my ($job, $msg, $ex_status) = @_;
54 0 ▶ if ($job->did_something) {
Branch: 1 branch
BranchTrueFalseTotal
if ($job->did_something) 0 0 0
55 0 $job->debug("can't call 'failed' on already finished job");
56 0 return 0;
57 }
58  
59 ## If this job class specifies that jobs should be retried,
60 ## update the run_after if necessary, but keep the job around.
61  
62 # [LH] [2013-10-04]: Use active_worker_class instead of funcname if AWC is set.
63 0 ▶ my $class = $job->{active_worker_class} || $job->funcname;
Condition0%0/3
$job->{'active_worker_class'} || $job->funcname
l!l&&r!l&&!r
000
MC/DC0%0/2
$job->{'active_worker_class'} || $job->funcname
$job->{'active_worker_class'} $job->funcname
Truth table0%0/3
A || B
A= $job->{'active_worker_class'}B= $job->funcname
ABresult
1X1
011
000
64 0 my $failures = $job->failures + 1; # include this one, since we haven't ->add_failure yet
65 0 my $max_retries = $class->max_retries($job);
66  
67 0 $job->debug("job failed. considering retry. is max_retries of $max_retries >= failures of $failures?");
68 0 $job->_failed($msg, $ex_status, $max_retries >= $failures, $failures);
69 }
70  
71 0 ▶sub _failed {
Subroutine _failed: not called CC=6 SCAR=37.4
72 0 my ($job, $msg, $exit_status, $_retry, $failures) = @_;
73 0 $job->did_something(1);
74 0 ▶ $job->debug("job failed: " . ($msg || "<no message>"));
Condition0%0/2
$msg || '<no message>'
l!l
00
MC/DC0%0/1
$msg || '<no message>'
$msg
Truth table0%0/2
A
A= $msg
Aresult
11
00
75  
76 ## Mark the failure in the error table.
77 0 $job->add_failure($msg);
78  
79 0 ▶ if ($_retry) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_retry) { } 0 0 0
80 # [LH] [2013-10-04]: Use active_worker_class instead of funcname if AWC is set.
81 0 ▶ my $class = $job->{active_worker_class} || $job->funcname;
Condition0%0/3
$job->{'active_worker_class'} || $job->funcname
l!l&&r!l&&!r
000
MC/DC0%0/2
$job->{'active_worker_class'} || $job->funcname
$job->{'active_worker_class'} $job->funcname
Truth table0%0/3
A || B
A= $job->{'active_worker_class'}B= $job->funcname
ABresult
1X1
011
000
82 0 ▶ if (my $delay = $class->retry_delay($failures)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $delay = $class->retry_delay($failures)) 0 0 0
83 0 $job->run_after(time() + $delay);
84 }
85 0 $job->grabbed_until(0);
86 0 $job->driver->update($job);
87 } else {
88 0 ▶ $job->set_exit_status($exit_status || 1);
Condition0%0/2
$exit_status || 1
l!l
00
MC/DC0%0/1
$exit_status || 1
$exit_status
Truth table0%0/2
A
A= $exit_status
Aresult
11
00
89 0 $job->driver->remove($job);
90 }
91 }
92  
93  
94 1 1;
95 __END__
« Helios/ObjectDriver/DBI.pm ↑ Summary Helios/Logger/Internal.pm »