line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Qless::Client; |
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Qless::Client |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=cut |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
127753
|
use strict; use warnings; |
|
1
|
|
|
1
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
9
|
1
|
|
|
1
|
|
979
|
use JSON::XS qw(decode_json); |
|
1
|
|
|
|
|
3814
|
|
|
1
|
|
|
|
|
57
|
|
10
|
1
|
|
|
1
|
|
755
|
use Sys::Hostname qw(hostname); |
|
1
|
|
|
|
|
1042
|
|
|
1
|
|
|
|
|
54
|
|
11
|
1
|
|
|
1
|
|
2334
|
use Time::HiRes qw(); |
|
1
|
|
|
|
|
1766
|
|
|
1
|
|
|
|
|
25
|
|
12
|
1
|
|
|
1
|
|
540
|
use Qless::Lua; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
13
|
1
|
|
|
1
|
|
493
|
use Qless::Config; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
14
|
1
|
|
|
1
|
|
404
|
use Qless::Workers; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
15
|
1
|
|
|
1
|
|
425
|
use Qless::Queues; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
16
|
1
|
|
|
1
|
|
529
|
use Qless::ClientJobs; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
193
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 METHODS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head2 C |
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
sub new { |
23
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
24
|
0
|
|
|
|
|
|
my ($redis) = @_; |
25
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
$class = ref $class if ref $class; |
27
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Redis handler |
30
|
0
|
|
|
|
|
|
$self->{'redis'} = $redis; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# worker name |
33
|
0
|
|
|
|
|
|
$self->{'worker_name'} = hostname.'-'.$$; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
$self->{'jobs'} = Qless::ClientJobs->new($self); |
36
|
0
|
|
|
|
|
|
$self->{'queues'} = Qless::Queues->new($self); |
37
|
0
|
|
|
|
|
|
$self->{'workers'} = Qless::Workers->new($self); |
38
|
0
|
|
|
|
|
|
$self->{'config'} = Qless::Config->new($self); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$self->_mk_private_lua_method($_) foreach ('cancel', 'config', 'complete', 'depends', 'fail', 'failed', 'get', 'heartbeat', 'jobs', 'peek', |
41
|
|
|
|
|
|
|
'pop', 'priority', 'put', 'queues', 'recur', 'retry', 'stats', 'tag', 'track', 'unfail', 'workers'); |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$self; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _mk_private_lua_method { |
47
|
0
|
|
|
0
|
|
|
my ($self, $name) = @_; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $script = Qless::Lua->new($name, $self->{'redis'}); |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
1
|
|
5
|
no strict qw(refs); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
52
|
1
|
|
|
1
|
|
12
|
no warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
86
|
|
53
|
0
|
|
|
|
|
|
my $subname = __PACKAGE__.'::_'.$name; |
54
|
0
|
|
|
|
|
|
*{$subname} = sub { |
55
|
0
|
|
|
0
|
|
|
my $self = shift; |
56
|
0
|
|
|
|
|
|
$script->(@_); |
57
|
0
|
|
|
|
|
|
}; |
58
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
59
|
1
|
|
|
1
|
|
6
|
use strict qw(refs); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
414
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 C |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Begin tracking the job |
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
sub track { |
67
|
0
|
|
|
0
|
1
|
|
my ($self, $jid) = @_; |
68
|
0
|
|
|
|
|
|
return $self->_track([], 'track', $jid, Time::HiRes::time); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 C |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Stop tracking the job |
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
sub untrack { |
76
|
0
|
|
|
0
|
1
|
|
my ($self, $jid) = @_; |
77
|
0
|
|
|
|
|
|
return $self->_track([], 'untrack', $jid, Time::HiRes::time); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 C |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
The most common tags among jobs |
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
sub tags { |
85
|
0
|
|
|
0
|
1
|
|
my ($self, $offset, $count) = @_; |
86
|
0
|
|
0
|
|
|
|
$offset ||= 0; |
87
|
0
|
|
0
|
|
|
|
$count ||= 100; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return decode_json($self->_tag([], 'top', $offset, $count)); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 C |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Listen for a single event |
95
|
|
|
|
|
|
|
=cut |
96
|
0
|
|
|
0
|
1
|
|
sub event { } |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 C |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Listen indefinitely for all events |
101
|
|
|
|
|
|
|
=cut |
102
|
0
|
|
|
0
|
1
|
|
sub events { } |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 C |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Move jobs from the failed group to the provided queue |
107
|
|
|
|
|
|
|
=cut |
108
|
|
|
|
|
|
|
sub unfail { |
109
|
0
|
|
|
0
|
1
|
|
my ($self, $group, $queue, $count) = @_; |
110
|
0
|
|
0
|
|
|
|
return $self->_unfail([], Time::HiRes::time, $group, $queue, $count||500); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# accessors |
114
|
|
|
|
|
|
|
=head2 C |
115
|
|
|
|
|
|
|
=cut |
116
|
0
|
|
|
0
|
0
|
|
sub config { $_[0]->{'config'} }; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 C |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
0
|
0
|
|
0
|
1
|
|
sub workers { $#_ == 1 ? $_[0]->{'workers'}->item($_[1]) : $_[0]->{'workers'} } |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 C |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
If the name is specified, this method gets or creates a queue with that name. Otherwise it returns L object; |
127
|
|
|
|
|
|
|
=cut |
128
|
0
|
0
|
|
0
|
1
|
|
sub queues { $#_ == 1 ? $_[0]->{'queues'}->item($_[1]) : $_[0]->{'queues'} } |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 C |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
If jid is specified this method returns a job object corresponding to that jid, or C if it doesn't exist. Otherwise it returns L object |
133
|
|
|
|
|
|
|
=cut |
134
|
0
|
0
|
|
0
|
1
|
|
sub jobs { $#_ == 1 ? $_[0]->{'jobs'}->item($_[1]) : $_[0]->{'jobs'} } |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 C |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
139
|
|
|
|
|
|
|
|
140
|
0
|
0
|
|
0
|
1
|
|
sub worker_name { $#_ == 1 ? $_[0]->{'worker_name'} = $_[1] : $_[0]->{'worker_name'} } |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 C |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
0
|
1
|
|
sub redis { $_[0]->{'redis'} } |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |