line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Qless::Job; |
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Qless::Job |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=cut |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use strict; use warnings; |
|
1
|
|
|
1
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
9
|
1
|
|
|
1
|
|
5
|
use base 'Qless::BaseJob'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
460
|
|
10
|
1
|
|
|
1
|
|
7
|
use Qless::Utils qw(fix_empty_array); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
41
|
|
11
|
1
|
|
|
1
|
|
4
|
use JSON::XS qw(decode_json encode_json); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
12
|
1
|
|
|
1
|
|
1087
|
use Class::Load qw(try_load_class); |
|
1
|
|
|
|
|
33618
|
|
|
1
|
|
|
|
|
58
|
|
13
|
1
|
|
|
1
|
|
9
|
use Time::HiRes qw(); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1116
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
my ($client, $args) = @_; |
19
|
|
|
|
|
|
|
|
20
|
0
|
0
|
|
|
|
|
$class = ref $class if ref $class; |
21
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new($client, $args); |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
foreach my $key (qw(state tracked failure history dependents dependencies)) { |
24
|
0
|
|
|
|
|
|
$self->{$key} = $args->{ $key }; |
25
|
|
|
|
|
|
|
} |
26
|
0
|
|
|
|
|
|
$self->{'dependents'} = fix_empty_array($self->{'dependents'}); |
27
|
0
|
|
|
|
|
|
$self->{'dependencies'} = fix_empty_array($self->{'dependencies'}); |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
$self->{'expires_at'} = $args->{'expires'}; |
30
|
0
|
|
|
|
|
|
$self->{'original_retries'} = $args->{'retries'}; |
31
|
0
|
|
|
|
|
|
$self->{'retries_left'} = $args->{'remaining'}; |
32
|
0
|
|
|
|
|
|
$self->{'worker_name'} = $args->{'worker'}; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
$self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
0
|
0
|
|
sub state { $_[0]->{'state'} } |
38
|
0
|
|
|
0
|
0
|
|
sub tracked { $_[0]->{'tracked'} } |
39
|
0
|
|
|
0
|
0
|
|
sub failure { $_[0]->{'failure'} } |
40
|
0
|
|
|
0
|
0
|
|
sub history { $_[0]->{'history'} } |
41
|
0
|
|
|
0
|
0
|
|
sub dependents { $_[0]->{'dependents'} } |
42
|
0
|
|
|
0
|
0
|
|
sub dependencies { $_[0]->{'dependencies'} } |
43
|
0
|
|
|
0
|
0
|
|
sub expires_at { $_[0]->{'expires_at'} } |
44
|
0
|
|
|
0
|
0
|
|
sub original_retries { $_[0]->{'original_retries'} } |
45
|
0
|
|
|
0
|
0
|
|
sub retries_left { $_[0]->{'retries_left'} } |
46
|
0
|
|
|
0
|
0
|
|
sub worker_name { $_[0]->{'worker_name'} } |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub ttl { |
49
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
50
|
0
|
|
|
|
|
|
return $self->{'expires_at'} - Time::HiRes::time; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub process { |
54
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $class = $self->klass; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my ($loaded, $error_message) = try_load_class($class); |
59
|
0
|
0
|
|
|
|
|
if(!$loaded) { |
60
|
0
|
|
|
|
|
|
return $self->fail($self->queue_name.'-class-missing', $class. ' is missing: '.$error_message); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $method; |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
if ($class->can($self->queue_name)) { |
|
|
0
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$method = $self->queue_name; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
elsif ($class->can('process')) { |
69
|
0
|
|
|
|
|
|
$method = 'process'; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
if (!$method) { |
73
|
0
|
|
|
|
|
|
return $self->fail($self->queue_name.'-method-missing', $class. ' is missing a method "'.$self->queue_name.'" or "process"'); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
eval { |
77
|
0
|
|
|
|
|
|
$class->$method($self); |
78
|
|
|
|
|
|
|
}; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
if ($@) { |
81
|
0
|
|
|
|
|
|
print STDERR "Error: $@\n"; |
82
|
0
|
|
|
|
|
|
return $self->fail($self->queue_name.'-'.$class.'-'.$method, $@); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub move { |
88
|
0
|
|
|
0
|
0
|
|
my ($self, $queue, $delay, $depends) = @_; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
0
|
|
|
|
return $self->{'client'}->_put([$queue], |
|
|
|
0
|
|
|
|
|
91
|
|
|
|
|
|
|
$self->jid, |
92
|
|
|
|
|
|
|
$self->klass, |
93
|
|
|
|
|
|
|
encode_json($self->data), |
94
|
|
|
|
|
|
|
Time::HiRes::time, |
95
|
|
|
|
|
|
|
$delay||0, |
96
|
|
|
|
|
|
|
'depends', encode_json($depends||[]) |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub complete { |
101
|
0
|
|
|
0
|
0
|
|
my ($self, $next, $delay, $depends) = @_; |
102
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
if ($next) { |
104
|
0
|
|
0
|
|
|
|
return $self->client->_complete([], $self->jid, $self->client->worker_name, $self->queue_name, |
|
|
|
0
|
|
|
|
|
105
|
|
|
|
|
|
|
Time::HiRes::time, encode_json($self->data), 'next', $next, 'delay', $delay||0, 'depends', encode_json($depends||[]) |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
else { |
109
|
0
|
|
|
|
|
|
return $self->client->_complete([], $self->jid, $self->client->worker_name, $self->queue_name, |
110
|
|
|
|
|
|
|
Time::HiRes::time, encode_json($self->data) |
111
|
|
|
|
|
|
|
); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub heartbeat { |
116
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
0
|
|
|
|
return $self->{'expires_at'} = $self->client->_heartbeat([], |
119
|
|
|
|
|
|
|
$self->jid, $self->client->worker_name, Time::HiRes::time, encode_json($self->data) |
120
|
|
|
|
|
|
|
) || 0; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub fail { |
125
|
0
|
|
|
0
|
0
|
|
my ($self, $group, $message) = @_; |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
return $self->client->_fail([], $self->jid, $self->client->worker_name, $group, $message, Time::HiRes::time, encode_json($self->data)); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub track { |
131
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
return $self->client->_track([], 'track', $self->jid, Time::HiRes::time); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub untrack { |
137
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
return $self->client->_track([], 'untrack', $self->jid, Time::HiRes::time); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub retry { |
143
|
0
|
|
|
0
|
0
|
|
my ($self, $delay) = @_; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
0
|
|
|
|
return $self->client->_retry([], $self->jid, $self->queue_name, $self->worker_name, Time::HiRes::time, $delay||0); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub depend { |
149
|
0
|
|
|
0
|
0
|
|
my ($self, @args) = @_; |
150
|
0
|
|
|
|
|
|
return $self->client->_depends([], $self->jid, 'on', @args); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub undepend { |
154
|
0
|
|
|
0
|
0
|
|
my ($self, @args) = @_; |
155
|
0
|
0
|
|
|
|
|
if ($args[0] eq 'all') { |
156
|
0
|
|
|
|
|
|
return $self->client->_depends([], $self->jid, 'off', 'all'); |
157
|
|
|
|
|
|
|
} |
158
|
0
|
|
|
|
|
|
return $self->client->_depends([], $self->jid, 'off', @args); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; |