| 1 | package Qless::Job; | ||||||||||||||||||||||
| 2 | =head1 NAME | ||||||||||||||||||||||
| 3 | |||||||||||||||||||||||
| 4 | Qless::Job | ||||||||||||||||||||||
| 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 base 'Qless::BaseJob'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 10 | 1 | ▶ | use Qless::Utils qw(fix_empty_array); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | 1 | ▶ | use JSON::XS qw(decode_json encode_json); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 12 | 1 | ▶ | use Class::Load qw(try_load_class); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | 1 | ▶ | use Time::HiRes qw(); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 14 | |||||||||||||||||||||||
| 15 | 0 | ▶ | sub new { | ||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||
| 16 | 0 | my $class = shift; | |||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | 0 | my ($client, $args) = @_; | |||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | 0 | ▶ | $class = ref $class if ref $class; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 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 | ▶ | sub state { $_[0]->{'state'} } | ||||||||||||||||||||
|
Subroutine
state: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 38 | 0 | ▶ | sub tracked { $_[0]->{'tracked'} } | ||||||||||||||||||||
|
Subroutine
tracked: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 39 | 0 | ▶ | sub failure { $_[0]->{'failure'} } | ||||||||||||||||||||
|
Subroutine
failure: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 40 | 0 | ▶ | sub history { $_[0]->{'history'} } | ||||||||||||||||||||
|
Subroutine
history: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 41 | 0 | ▶ | sub dependents { $_[0]->{'dependents'} } | ||||||||||||||||||||
|
Subroutine
dependents: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 42 | 0 | ▶ | sub dependencies { $_[0]->{'dependencies'} } | ||||||||||||||||||||
|
Subroutine
dependencies: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 43 | 0 | ▶ | sub expires_at { $_[0]->{'expires_at'} } | ||||||||||||||||||||
|
Subroutine
expires_at: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 44 | 0 | ▶ | sub original_retries { $_[0]->{'original_retries'} } | ||||||||||||||||||||
|
Subroutine
original_retries: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 45 | 0 | ▶ | sub retries_left { $_[0]->{'retries_left'} } | ||||||||||||||||||||
|
Subroutine
retries_left: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 46 | 0 | ▶ | sub worker_name { $_[0]->{'worker_name'} } | ||||||||||||||||||||
|
Subroutine
worker_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 47 | |||||||||||||||||||||||
| 48 | 0 | ▶ | sub ttl { | ||||||||||||||||||||
|
Subroutine
ttl: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 49 | 0 | my ($self) = @_; | |||||||||||||||||||||
| 50 | 0 | return $self->{'expires_at'} - Time::HiRes::time; | |||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||
| 52 | |||||||||||||||||||||||
| 53 | 0 | ▶ | sub process { | ||||||||||||||||||||
|
Subroutine
process: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||
| 54 | 0 | my ($self) = @_; | |||||||||||||||||||||
| 55 | |||||||||||||||||||||||
| 56 | 0 | my $class = $self->klass; | |||||||||||||||||||||
| 57 | |||||||||||||||||||||||
| 58 | 0 | my ($loaded, $error_message) = try_load_class($class); | |||||||||||||||||||||
| 59 | 0 | ▶ | if(!$loaded) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 60 | 0 | return $self->fail($self->queue_name.'-class-missing', $class. ' is missing: '.$error_message); | |||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||
| 62 | |||||||||||||||||||||||
| 63 | 0 | my $method; | |||||||||||||||||||||
| 64 | |||||||||||||||||||||||
| 65 | 0 | ▶ | if ($class->can($self->queue_name)) { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 66 | 0 | $method = $self->queue_name; | |||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||
| 68 | elsif ($class->can('process')) { | ||||||||||||||||||||||
| 69 | 0 | $method = 'process'; | |||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||
| 71 | |||||||||||||||||||||||
| 72 | 0 | ▶ | if (!$method) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 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 | ▶ | if ($@) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 81 | 0 | print STDERR "Error: $@\n"; | |||||||||||||||||||||
| 82 | 0 | return $self->fail($self->queue_name.'-'.$class.'-'.$method, $@); | |||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||
| 84 | |||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||
| 86 | |||||||||||||||||||||||
| 87 | 0 | ▶ | sub move { | ||||||||||||||||||||
|
Subroutine
move: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||
| 88 | 0 | my ($self, $queue, $delay, $depends) = @_; | |||||||||||||||||||||
| 89 | |||||||||||||||||||||||
| 90 | 0 | ▶ | return $self->{'client'}->_put([$queue], | ||||||||||||||||||||
|
Condition0%0/4
$delay || 0
$depends || []
MC/DC0%0/1
$delay || 0
$delay
MC/DC0%0/1
$depends || []
$depends
Truth table0%0/2
A
A= $delay
Truth table0%0/2
A
A= $depends
| |||||||||||||||||||||||
| 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 | 0 | ▶ | sub complete { | ||||||||||||||||||||
|
Subroutine
complete: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||
| 101 | 0 | my ($self, $next, $delay, $depends) = @_; | |||||||||||||||||||||
| 102 | |||||||||||||||||||||||
| 103 | 0 | ▶ | if ($next) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 104 | 0 | ▶ | return $self->client->_complete([], $self->jid, $self->client->worker_name, $self->queue_name, | ||||||||||||||||||||
|
Condition0%0/4
$delay || 0
$depends || []
MC/DC0%0/1
$delay || 0
$delay
MC/DC0%0/1
$depends || []
$depends
Truth table0%0/2
A
A= $delay
Truth table0%0/2
A
A= $depends
| |||||||||||||||||||||||
| 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 | 0 | ▶ | sub heartbeat { | ||||||||||||||||||||
|
Subroutine
heartbeat: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||
| 116 | 0 | my ($self) = @_; | |||||||||||||||||||||
| 117 | |||||||||||||||||||||||
| 118 | 0 | ▶ | return $self->{'expires_at'} = $self->client->_heartbeat([], | ||||||||||||||||||||
|
Condition0%0/2
$self->client->_heartbeat([], $self->jid, $self->client->worker_name, &Time::HiRes::time(), &encode_json(scalar $self->data)) || 0
MC/DC0%0/1
$self->client->_heartbeat([], $self->jid, $self->client->worker_name, &Time::HiRes::time(), &encode_json(scalar $self->data)) || 0
$self->client->_heartbeat([], $self->jid, $self->client->worker_name, &Time::HiRes::time(), &encode_json(scalar $self->data))
Truth table0%0/2
A
A= $self->client->_heartbeat([], $self->jid, $self->client->worker_name, &Time::HiRes::time(), &encode_json(scalar $self->data))
| |||||||||||||||||||||||
| 119 | $self->jid, $self->client->worker_name, Time::HiRes::time, encode_json($self->data) | ||||||||||||||||||||||
| 120 | ) || 0; | ||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||
| 122 | |||||||||||||||||||||||
| 123 | |||||||||||||||||||||||
| 124 | 0 | ▶ | sub fail { | ||||||||||||||||||||
|
Subroutine
fail: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 125 | 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 | 0 | ▶ | sub track { | ||||||||||||||||||||
|
Subroutine
track: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 131 | 0 | my ($self) = @_; | |||||||||||||||||||||
| 132 | |||||||||||||||||||||||
| 133 | 0 | return $self->client->_track([], 'track', $self->jid, Time::HiRes::time); | |||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||
| 135 | |||||||||||||||||||||||
| 136 | 0 | ▶ | sub untrack { | ||||||||||||||||||||
|
Subroutine
untrack: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 137 | 0 | my ($self) = @_; | |||||||||||||||||||||
| 138 | |||||||||||||||||||||||
| 139 | 0 | return $self->client->_track([], 'untrack', $self->jid, Time::HiRes::time); | |||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||
| 141 | |||||||||||||||||||||||
| 142 | 0 | ▶ | sub retry { | ||||||||||||||||||||
|
Subroutine
retry: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||
| 143 | 0 | my ($self, $delay) = @_; | |||||||||||||||||||||
| 144 | |||||||||||||||||||||||
| 145 | 0 | ▶ | return $self->client->_retry([], $self->jid, $self->queue_name, $self->worker_name, Time::HiRes::time, $delay||0); | ||||||||||||||||||||
|
Condition0%0/2
$delay || 0
MC/DC0%0/1
$delay || 0
$delay
Truth table0%0/2
A
A= $delay
| |||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||
| 147 | |||||||||||||||||||||||
| 148 | 0 | ▶ | sub depend { | ||||||||||||||||||||
|
Subroutine
depend: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 149 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||
| 150 | 0 | return $self->client->_depends([], $self->jid, 'on', @args); | |||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||
| 152 | |||||||||||||||||||||||
| 153 | 0 | ▶ | sub undepend { | ||||||||||||||||||||
|
Subroutine
undepend: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||
| 154 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||
| 155 | 0 | ▶ | if ($args[0] eq 'all') { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 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 | 1; | |||||||||||||||||||||