lib/Qudo/Worker.pm

filter: Statementstmt 25.9% 7 / 27 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 28.5% 2 / 7 Podpod 80.0% 4 / 5 totaltotal 23.6% 13 / 55 CC 7 SCAR 34.3
CC
7
Cov
18%
work_safely
56.0
max_retries
2.0
retry_delay
2.0
CRAP 30.9
↑ Summary blib/lib/Qudo/Test.pm »
1 package Qudo::Worker;
2 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 0 ▶sub max_retries { 0 }
Subroutine max_retries: not called CC=1 SCAR=6.9
Pod documented
6 0 ▶sub retry_delay { 0 }
Subroutine retry_delay: not called CC=1 SCAR=6.9
Pod documented
7 0 ▶sub grab_for { 60*60 } # default setting 1 hour
Subroutine grab_for: not called CC=1 SCAR=6.9
Pod documented
8 0 ▶sub set_job_status { 0 } # job process status store for job_status table.
Subroutine set_job_status: not called CC=1 SCAR=6.9
Pod documented
9  
10 0 ▶sub work_safely {
Subroutine work_safely: not called CC=7 SCAR=40.3
Pod undocumented
11 0 my ($class, $job) = @_;
12  
13 0 ▶ if ($job->funcname->set_job_status) {
Branch: 1 branch
BranchTrueFalseTotal
if ($job->funcname->set_job_status) 0 0 0
14 0 $job->job_start_time = time;
15 }
16  
17 0 my $res;
18 0 eval {
19 0 $res = $class->work($job);
20 };
21  
22 0 ▶ if ($job->is_aborted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($job->is_aborted) 0 0 0
23 0 $job->dequeue;
24 0 return $res;
25 }
26  
27 0 ▶ if ( (my $e = $@) || ! $job->is_completed ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $@ or not $job->is_completed) { } 0 0 0
Condition0%0/3
my $e = $@ or not $job->is_completed
l!l&&r!l&&!r
000
MC/DC0%0/2
my $e = $@ or not $job->is_completed
my $e = $@ not $job->is_completed
Truth table0%0/3
A or not(B)
A= my $e = $@B= not $job->is_completed
ABresult
1X1
011
000
28 0 ▶ if ( $job->retry_cnt < $class->max_retries ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($job->retry_cnt < $class->max_retries) { } 0 0 0
29 0 $job->reenqueue(
30 {
31 grabbed_until => 0,
32 retry_cnt => $job->retry_cnt + 1,
33 retry_delay => $class->retry_delay($job),
34 }
35 );
36 } else {
37 0 $job->dequeue;
38 }
39 0 ▶ $job->failed("$e" || 'Job did not explicitly complete or fail');
Condition0%0/2
"$e" || 'Job did not explicitly complete or fail'
l!l
00
MC/DC0%0/1
"$e" || 'Job did not explicitly complete or fail'
"$e"
Truth table0%0/2
A
A= "$e"
Aresult
11
00
40 } else {
41 0 $job->dequeue;
42 }
43  
44 0 return $res;
45 }
46  
47 =head1 NAME
48  
49 Qudo::Worker - superclass for defining task behavior of Qudo's work
50  
51 =head1 SYNOPSIS
52  
53 package Myworker;
54 use base qw/ Qudo::Worker /;
55  
56 sub work {
57 my ($self , $job ) = @_;
58  
59 my $job_arg = $job->arg();
60 print "This is Myworker's work. job has argument == $job_arg \n";
61  
62 $job->completed(); # or die or $job->abort
63 }
64 1;
65  
66 =head1 DESCRIPTION
67  
68 Qudo::Worker is based on all your work class of using Qudo.
69  
70 Your application have to inherit Qudo::Worker anyway.
71 And it has to have 'work' method too.
72  
73 'work' method accept Qudo::Job object at parameter.
74 If your work complete , you may call Qudo::Job->complete() method.
75  
76 =head1 WORKER SETTING
77  
78 =head2 max_retries
79  
80 package Your::Worker;
81 use base 'Qudo::Worker';
82 sub max_retries { 2 }
83 sub work { ... }
84  
85 How many times it retries if worker doesn't succeed is set.
86 It is retried two times in this example.
87 By default, return 0. no retry.
88  
89 =head2 retry_delay
90  
91 package Your::Worker;
92 use base 'Qudo::Worker';
93 sub retry_delay { 10 }
94 sub work { ... }
95  
96 returns the number of seconds after a failure workers should wait until
97 retry a job that has already failed retry_delay times.
98 By default,return 0 seconds
99  
100 =head2 grab_for
101  
102 package Your::Worker;
103 use base 'Qudo::Worker';
104 sub grab_for { 3600 }
105 sub work { ... }
106  
107 Returns the number of seconds workers of this class will claim a grabbed a job.
108 By default,return 3600 seconds.
109  
110 =head2 set_job_status
111  
112 package Your::Worker;
113 use base 'Qudo::Worker';
114 sub set_job_status { 1 }
115 sub work { ... }
116  
117 set the flag.
118 When flag is the truth, the processing result of worker is preserved in DB.
119  
120 =cut
121  
122 27 1;
123  
↑ Summary blib/lib/Qudo/Test.pm »