Qless/Client.pm

filter: Statementstmt 55.1% 43 / 78 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 48.2% 14 / 29 Podpod 92.3% 12 / 13 totaltotal 49.6% 69 / 139 CC 10 SCAR 14.3
CC
10
Cov
46%
new
12.0
tags
12.0
unfail
6.0
CRAP 4.2
« Qless/RecurringJob.pm ↑ Summary Qless/BaseJob.pm »
1 package Qless::Client;
2 =head1 NAME
3  
4 Qless::Client
5  
6 =cut
7  
8 1 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use JSON::XS qw(decode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Sys::Hostname qw(hostname);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Time::HiRes qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Qless::Lua;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Qless::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Qless::Workers;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Qless::Queues;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Qless::ClientJobs;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 =head1 METHODS
19  
20 =head2 C<new>
21 =cut
22 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
23 0 my $class = shift;
24 0 my ($redis) = @_;
25  
26 0 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
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 0 ▶sub _mk_private_lua_method {
Subroutine _mk_private_lua_method: not called CC=1 SCAR=1.5
47 0 my ($self, $name) = @_;
48  
49 0 my $script = Qless::Lua->new($name, $self->{'redis'});
50  
51 1 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
52 1 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 0 my $subname = __PACKAGE__.'::_'.$name;
54 0 ▶ *{$subname} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 0 my $self = shift;
56 0 $script->(@_);
57 0 };
58 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 1 ▶ use strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
60 }
61  
62 =head2 C<track($jid)>
63  
64 Begin tracking the job
65 =cut
66 0 ▶sub track {
Subroutine track: not called CC=1 SCAR=6.9
Pod documented
67 0 my ($self, $jid) = @_;
68 0 return $self->_track([], 'track', $jid, Time::HiRes::time);
69 }
70  
71 =head2 C<untrack($jid)>
72  
73 Stop tracking the job
74 =cut
75 0 ▶sub untrack {
Subroutine untrack: not called CC=1 SCAR=6.9
Pod documented
76 0 my ($self, $jid) = @_;
77 0 return $self->_track([], 'untrack', $jid, Time::HiRes::time);
78 }
79  
80 =head2 C<tags([$offset, $count])>
81  
82 The most common tags among jobs
83 =cut
84 0 ▶sub tags {
Subroutine tags: not called CC=3 SCAR=24.8
Pod documented
85 0 my ($self, $offset, $count) = @_;
86 0 ▶ $offset ||= 0;
Condition0%0/2
$offset ||= 0
l!l
00
MC/DC0%0/1
$offset ||= 0
$offset
Truth table0%0/2
A
A= $offset
Aresult
11
00
87 0 ▶ $count ||= 100;
Condition0%0/2
$count ||= 100
l!l
00
MC/DC0%0/1
$count ||= 100
$count
Truth table0%0/2
A
A= $count
Aresult
11
00
88  
89 0 return decode_json($self->_tag([], 'top', $offset, $count));
90 }
91  
92 =head2 C<event - TBD>
93  
94 Listen for a single event
95 =cut
96 0 ▶sub event { }
Subroutine event: not called CC=1 SCAR=0.0
Pod documented
97  
98 =head2 C<events -TBD>
99  
100 Listen indefinitely for all events
101 =cut
102 0 ▶sub events { }
Subroutine events: not called CC=1 SCAR=0.0
Pod documented
103  
104 =head2 C<unfail($group, $queue[, $count])>
105  
106 Move jobs from the failed group to the provided queue
107 =cut
108 0 ▶sub unfail {
Subroutine unfail: not called CC=2 SCAR=17.9
Pod documented
109 0 my ($self, $group, $queue, $count) = @_;
110 0 ▶ return $self->_unfail([], Time::HiRes::time, $group, $queue, $count||500);
Condition0%0/2
$count || 500
l!l
00
MC/DC0%0/1
$count || 500
$count
Truth table0%0/2
A
A= $count
Aresult
11
00
111 }
112  
113 # accessors
114 =head2 C<config>
115 =cut
116 0 ▶sub config { $_[0]->{'config'} };
Subroutine config: not called CC=1 SCAR=6.9
Pod undocumented
117  
118 =head2 C<workers([$name])>
119  
120 =cut
121  
122 0 ▶sub workers { $#_ == 1 ? $_[0]->{'workers'}->item($_[1]) : $_[0]->{'workers'} }
Subroutine workers: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$#_ == 1 ? : 0 0 0
123  
124 =head2 C<queues([$name])>
125  
126 If the name is specified, this method gets or creates a queue with that name. Otherwise it returns L<Qless::Queues> object;
127 =cut
128 0 ▶sub queues { $#_ == 1 ? $_[0]->{'queues'}->item($_[1]) : $_[0]->{'queues'} }
Subroutine queues: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$#_ == 1 ? : 0 0 0
129  
130 =head2 C<jobs([$jid])>
131  
132 If jid is specified this method returns a job object corresponding to that jid, or C<undef> if it doesn't exist. Otherwise it returns L<Qless::ClientJobs> object
133 =cut
134 0 ▶sub jobs { $#_ == 1 ? $_[0]->{'jobs'}->item($_[1]) : $_[0]->{'jobs'} }
Subroutine jobs: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$#_ == 1 ? : 0 0 0
135  
136 =head2 C<worker_name>
137  
138 =cut
139  
140 0 ▶sub worker_name { $#_ == 1 ? $_[0]->{'worker_name'} = $_[1] : $_[0]->{'worker_name'} }
Subroutine worker_name: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$#_ == 1 ? : 0 0 0
141  
142 =head2 C<redis>
143  
144 =cut
145  
146 0 ▶sub redis { $_[0]->{'redis'} }
Subroutine redis: not called CC=1 SCAR=6.9
Pod documented
147  
148 1 1;
« Qless/RecurringJob.pm ↑ Summary Qless/BaseJob.pm »