lib/Qudo/Worker.pm

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