Queue/Delay.pm

filter: Statementstmt 34.2% 12 / 35 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 22.2% 2 / 9 Podpod 0.0% 0 / 2 totaltotal 22.5% 14 / 62 CC 7 SCAR 15.5
CC
7
Cov
26%
wait
12.0
__ANON__
3.7
__ANON__
3.7
CRAP 4.7
« Queue.pm ↑ Summary Queue/Job.pm »
1 package MangoX::Queue::Delay;
2  
3 12 ▶use Mojo::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use Mojo::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 0 ▶has start => sub { $ENV{MANGOX_QUEUE_DELAY_START} // 0.1 };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Condition0%0/2
$ENV{"MANGOX_QUEUE_DELAY_START"} // "0.1"
l!l
00
MC/DC0%0/1
$ENV{"MANGOX_QUEUE_DELAY_START"} // "0.1"
$ENV{"MANGOX_QUEUE_DELAY_START"}
Truth table0%0/2
A
A= $ENV{"MANGOX_QUEUE_DELAY_START"}
Aresult
11
00
7 0 ▶has current => sub { $ENV{MANGOX_QUEUE_DELAY_START} // 0.1 };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Condition0%0/2
$ENV{"MANGOX_QUEUE_DELAY_START"} // "0.1"
l!l
00
MC/DC0%0/1
$ENV{"MANGOX_QUEUE_DELAY_START"} // "0.1"
$ENV{"MANGOX_QUEUE_DELAY_START"}
Truth table0%0/2
A
A= $ENV{"MANGOX_QUEUE_DELAY_START"}
Aresult
11
00
8 0 ▶has increment => sub { $ENV{MANGOX_QUEUE_DELAY_INCREMENT} // 0.1 };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Condition0%0/2
$ENV{"MANGOX_QUEUE_DELAY_INCREMENT"} // "0.1"
l!l
00
MC/DC0%0/1
$ENV{"MANGOX_QUEUE_DELAY_INCREMENT"} // "0.1"
$ENV{"MANGOX_QUEUE_DELAY_INCREMENT"}
Truth table0%0/2
A
A= $ENV{"MANGOX_QUEUE_DELAY_INCREMENT"}
Aresult
11
00
9 0 ▶has maximum => sub { $ENV{MANGOX_QUEUE_DELAY_MAXIMUM} // 10 };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Condition0%0/2
$ENV{"MANGOX_QUEUE_DELAY_MAXIMUM"} // 10
l!l
00
MC/DC0%0/1
$ENV{"MANGOX_QUEUE_DELAY_MAXIMUM"} // 10
$ENV{"MANGOX_QUEUE_DELAY_MAXIMUM"}
Truth table0%0/2
A
A= $ENV{"MANGOX_QUEUE_DELAY_MAXIMUM"}
Aresult
11
00
10  
11 0 ▶has log => sub { Mojo::Log->new->level('error') };
Subroutine __ANON__: not called CC=1 SCAR=1.2
12  
13 sub reset {
14 0 ▶ my ($self) = @_;
Subroutine reset: not called CC=1 SCAR=6.9
Pod undocumented
15
16 0 $self->log->debug("Reset delay to " . $self->start . " seconds");
17  
18 0 $self->current($self->start);
19 }
20  
21 sub wait {
22 0 ▶ my ($self, $callback) = @_;
Subroutine wait: not called CC=3 SCAR=24.8
Pod undocumented
23  
24 0 my $delay = $self->current;
25 0 $self->log->debug("Current delay is $delay seconds");
26  
27 0 my $incremented = $delay + $self->increment;
28 0 $self->log->debug("New delay is $incremented seconds");
29  
30 0 ▶ if($incremented > $self->maximum) {
Branch: 1 branch
BranchTrueFalseTotal
if ($incremented > $self->maximum) 0 0 0
31 0 $self->log->debug("Limiting delay to maximum " . $self->maximum . " seconds");
32 0 $incremented = $self->maximum;
33 }
34  
35 0 $self->current($incremented);
36  
37 0 ▶ if($callback) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callback) { } 0 0 0
38 0 $self->log->debug("Non-blocking delay for $delay seconds");
39 0 Mojo::IOLoop->timer($delay => $callback);
40 } else {
41 0 $self->log->debug("Sleeping for $delay seconds");
42 0 sleep $delay;
43 }
44  
45 0 return $delay;
46 }
47  
48 12 1;
« Queue.pm ↑ Summary Queue/Job.pm »