blib/lib/Qudo/Job.pm

filter: Statementstmt 12.7% 7 / 55 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 8.0% 2 / 25 Podpod 86.9% 20 / 23 totaltotal 25.8% 29 / 112 CC 6 SCAR 13.2
CC
6
Cov
11%
abort
12.0
completed
6.0
failed
6.0
CRAP 3.7
« blib/lib/Qudo/Manager.pm ↑ Summary blib/lib/Qudo/Driver/Skinny.pm »
1 package Qudo::Job;
2 33 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 33 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
6 0 my ($class, %args) = @_;
7 0 bless {%args}, $class;
8 }
9  
10 0 ▶sub id { $_[0]->{job_data}->{job_id} }
Subroutine id: not called CC=1 SCAR=6.9
Pod documented
11 0 ▶sub uniqkey { $_[0]->{job_data}->{job_uniqkey} }
Subroutine uniqkey: not called CC=1 SCAR=6.9
Pod documented
12 0 ▶sub func_id { $_[0]->{job_data}->{func_id} }
Subroutine func_id: not called CC=1 SCAR=6.9
Pod documented
13  
14 0 ▶sub funcname {
Subroutine funcname: not called CC=1 SCAR=6.9
Pod documented
15 0 my $self = shift;
16 0 $self->manager->funcid_to_name($self->func_id, $self->db);
17 }
18  
19 0 ▶sub retry_cnt { $_[0]->{job_data}->{job_retry_cnt} }
Subroutine retry_cnt: not called CC=1 SCAR=6.9
Pod documented
20 0 ▶sub grabbed_until { $_[0]->{job_data}->{job_grabbed_until} }
Subroutine grabbed_until: not called CC=1 SCAR=6.9
Pod documented
21 0 ▶sub priority { $_[0]->{job_data}->{job_priority} }
Subroutine priority: not called CC=1 SCAR=6.9
Pod documented
22 0 ▶sub arg : lvalue { $_[0]->{job_data}->{job_arg} }
Subroutine arg: not called CC=1 SCAR=6.9
Pod documented
23 0 ▶sub arg_origin : lvalue { $_[0]->{arg_origin} }
Subroutine arg_origin: not called CC=1 SCAR=6.9
Pod documented
24 0 ▶sub db { $_[0]->{db} }
Subroutine db: not called CC=1 SCAR=6.9
Pod documented
25  
26 0 ▶sub manager { $_[0]->{manager} }
Subroutine manager: not called CC=1 SCAR=6.9
Pod documented
27 0 ▶sub job_start_time : lvalue { $_[0]->{job_start_time} }
Subroutine job_start_time: not called CC=1 SCAR=6.9
Pod documented
28  
29 0 ▶sub completed {
Subroutine completed: not called CC=2 SCAR=17.9
Pod documented
30 0 my $self = shift;
31  
32 0 $self->{_complete} = 1;
33  
34 0 ▶ return unless $self->funcname->set_job_status;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->funcname->set_job_status 0 0 0
35 0 $self->manager->set_job_status($self, 'completed');
36 }
37  
38 0 ▶sub is_completed { $_[0]->{_complete} }
Subroutine is_completed: not called CC=1 SCAR=6.9
Pod documented
39 0 ▶sub is_aborted { $_[0]->{_abort} }
Subroutine is_aborted: not called CC=1 SCAR=6.9
Pod documented
40 0 ▶sub is_failed { $_[0]->{_fail} }
Subroutine is_failed: not called CC=1 SCAR=6.9
Pod documented
41  
42 0 ▶sub reenqueue {
Subroutine reenqueue: not called CC=1 SCAR=6.9
Pod undocumented
43 0 my ($self, $args) = @_;
44 0 $self->manager->reenqueue($self, $args);
45 }
46  
47 0 ▶sub dequeue {
Subroutine dequeue: not called CC=1 SCAR=6.9
Pod undocumented
48 0 my $self = shift;
49 0 $self->manager->dequeue($self);
50 }
51  
52 0 ▶sub error {
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
53 0 my ($self, ) = @_;
54 return $self->{_error}
55 0 }
56  
57 0 ▶sub failed {
Subroutine failed: not called CC=2 SCAR=17.9
Pod documented
58 0 my ($self, $error) = @_;
59  
60 0 $self->{_fail} = 1;
61 0 $self->{_error} = $error;
62  
63 0 ▶ if ($self->funcname->set_job_status) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->funcname->set_job_status) 0 0 0
64 0 $self->manager->set_job_status($self, 'failed');
65 }
66 0 $self->manager->job_failed($self, $error);
67 }
68  
69 0 ▶sub abort {
Subroutine abort: not called CC=3 SCAR=24.8
Pod documented
70 0 my ($self, $error) = @_;
71  
72 0 $self->{_abort} = 1;
73 0 ▶ $error ||= 'abort!!';
Condition0%0/2
$error ||= "abort!!"
l!l
00
MC/DC0%0/1
$error ||= "abort!!"
$error
Truth table0%0/2
A
A= $error
Aresult
11
00
74 0 $self->{_error} = $error;
75  
76 0 ▶ if ($self->funcname->set_job_status) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->funcname->set_job_status) 0 0 0
77 0 $self->manager->set_job_status($self, 'abort');
78 }
79 0 $self->manager->job_failed($self, $error);
80 }
81  
82 0 ▶sub replace {
Subroutine replace: not called CC=2 SCAR=17.9
Pod documented
83 0 my ($self, @jobs) = @_;
84  
85 0 my $db = $self->manager->driver_for($self->db);
86 0 $db->dbh->begin_work;
87  
88 0 for my $job (@jobs) {
89 0 $self->manager->enqueue(@$job, $self->db);
90 }
91  
92 0 $self->completed;
93  
94 0 $db->dbh->commit;
95 }
96  
97 =head1 NAME
98  
99 Qudo::Job - Qudo job class
100  
101 =head1 SYNOPSIS
102  
103 # You don't need to create job object by yourself.
104  
105 =head1 DESCRIPTION
106  
107 Qudo::Job object is passed to your worker and some hook points.
108  
109 =head1 METHODS
110  
111 =head2 id
112  
113 Returns job id.
114  
115 =head2 uniqkey
116  
117 Returns the job unique key.
118  
119 =head2 func_id
120  
121 Returns the function id of the job.
122  
123 =head2 funcname
124  
125 Returns the function name of the job.
126  
127 =head2 retry_cnt
128  
129 Returns how many times the job is retried.
130  
131 =head2 grabbed_until
132  
133 Returns time when job is grabbed.
134  
135 =head2 priority
136  
137 Returns the priority of the job.
138  
139 =head2 arg
140  
141 Returns the job argument.
142  
143 =head2 arg_origin
144  
145 Returns the original argument before a serializer change.
146  
147 =head2 db
148  
149 Returns the database the job belonging.
150  
151 =head2 manager
152  
153 Returns Qudo manager.
154  
155 =head2 job_start_time
156  
157 Returns time when job started.
158  
159 =head2 completed
160  
161 Set job as completed successfully.
162  
163 =head2 is_completed
164  
165 If job is completed, returns true.
166  
167 =head2 is_aborted
168  
169 If job is aborted, returns true.
170  
171 =head2 is_failed
172  
173 If job is failed, returns true.
174  
175 =head2 error
176  
177 Returns error message set in failed or abort
178  
179 =head2 failed
180  
181 $job->failed($reason);
182  
183 Don't use this method in your worker class.
184 Use die instead of this.
185 $reason is set as error and logged in exception_log.
186  
187 =head2 abort
188  
189 $job->abort($reason);
190  
191 This aborts job.
192 When this method is called, the job never retried even if you set retry_cnt is set.
193 But, if you override work_safely in Qudo::Worker, it is depends on your implementation.
194 $reason is set as error and logged in exception_log.
195  
196 =head2 replace
197  
198 $job->replace(['Worker::One', {arg => 'arg1'}], ['Worker::Another', {arg => 'arg2'}]);
199  
200 This enqueue new job(s) and current job itself is completed.
201  
202 =cut
203  
204 33 1;
« blib/lib/Qudo/Manager.pm ↑ Summary blib/lib/Qudo/Driver/Skinny.pm »