Mvalve/Reader.pm

filter: Statementstmt 31.3% 21 / 67 Branchbran 0.0% 0 / 34 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 21.5% 28 / 130 CC 22 SCAR 58.5
CC
22
Cov
19%
next
462.0
is_pending
6.0
BEGIN
1.0
CRAP 347.1
↑ Summary Mvalve/Base.pm »
1 # $Id$
2  
3 package Mvalve::Reader;
4 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Mvalve;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Mvalve::Const;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Mvalve::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 extends 'Mvalve::Base';
10  
11 1 has 'timeout' => (
12 is => 'rw',
13 isa => 'Num',
14 required => 1,
15 default => 60
16 );
17  
18 1 has 'throttler' => (
19 is => 'rw',
20 does => 'Mvalve::Throttler',
21 required => 1,
22 coerce => 1,
23 handles => [ qw(try_push fill) ],
24 );
25  
26 1 has 'drop_on_emergency' => (
27 is => 'rw',
28 isa => 'Bool',
29 required => 1,
30 default => 1,
31 );
32  
33 1 __PACKAGE__->meta->make_immutable;
34  
35 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 sub next
38 0 ▶{
Subroutine next: not called CC=21 SCAR=61.4
Pod documented
39 0 my $self = shift;
40  
41 0 my $qs = $self->queue_set;
42 0 my @names = $qs->as_q4m_args;
43  
44 0 ▶ Mvalve::trace("queue_wait with @names") if &Mvalve::Const::MVALVE_TRACE;
Branch: 1 branch
BranchTrueFalseTotal
if &Mvalve::Const::MVALVE_TRACE 0 0 0
45 0 my $table = $self->q_next(
46 table_conds => \@names,
47 timeout => $self->timeout + 0
48 );
49  
50 0 ▶ if (! $table) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($table) 0 0 0
51 0 ▶ Mvalve::trace( "q_next did not return a table name, simply returning" ) if &Mvalve::Const::MVALVE_TRACE;
Branch: 1 branch
BranchTrueFalseTotal
if &Mvalve::Const::MVALVE_TRACE 0 0 0
52 0 return ();
53 }
54  
55 0 ▶ Mvalve::trace( "issueing fetch on table '$table'") if &Mvalve::Const::MVALVE_TRACE;
Branch: 1 branch
BranchTrueFalseTotal
if &Mvalve::Const::MVALVE_TRACE 0 0 0
56  
57 0 my $message = $self->q_fetch(table => $table);
58 0 ▶ if (! $message) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($message) 0 0 0
59 0 ▶ Mvalve::trace( "q_fetch did not return a message, simply returning" ) if &Mvalve::Const::MVALVE_TRACE;
Branch: 1 branch
BranchTrueFalseTotal
if &Mvalve::Const::MVALVE_TRACE 0 0 0
60 0 return ();
61 }
62  
63 0 my $destination = $message->header( &Mvalve::Const::DESTINATION_HEADER );
64  
65 0 ▶ if (&Mvalve::Const::MVALVE_TRACE && $qs->is_timed( $table )) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Mvalve::Const::MVALVE_TRACE and $qs->is_timed($table)) 0 0 0
Condition0%0/3
&Mvalve::Const::MVALVE_TRACE and $qs->is_timed($table)
!ll&&!rl&&r
000
MC/DC0%0/2
&Mvalve::Const::MVALVE_TRACE and $qs->is_timed($table)
&Mvalve::Const::MVALVE_TRACE $qs->is_timed($table)
Truth table0%0/3
A and B
A= &Mvalve::Const::MVALVE_TRACEB= $qs->is_timed($table)
ABresult
0X0
100
111
66 0 Mvalve::trace( "we should have dispatched at " .
67 scalar( localtime( $message->header( &Mvalve::Const::RETRY_HEADER ) /100_000 ) ) );
68 }
69  
70 # destination is an abstract symbol representing the endpoint
71 # service name. this /could/ be used by the queue consumer, but it
72 # is *not* a
73  
74 0 my $emerg_key = [ $destination, 'emergency' ];
75 0 ▶ if ( $qs->is_emergency( $table ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qs->is_emergency($table)) 0 0 0
76 0 ▶ if ($self->drop_on_emergency) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->drop_on_emergency) { } 0 0 0
77 0 ▶ my $duration = $message->header(&Mvalve::Const::DURATION_HEADER)
Condition0%0/3
$message->header(&Mvalve::Const::DURATION_HEADER) || $self->throttler->interval
l!l&&r!l&&!r
000
MC/DC0%0/2
$message->header(&Mvalve::Const::DURATION_HEADER) || $self->throttler->interval
$message->header(&Mvalve::Const::DURATION_HEADER) $self->throttler->interval
Truth table0%0/3
A || B
A= $message->header(&Mvalve::Const::DURATION_HEADER)B= $self->throttler->interval
ABresult
1X1
011
000
78 || $self->throttler->interval;
79 0 $self->state_set($emerg_key, time + $duration);
80 }
81 else {
82 0 $self->fill( key => $destination )
83 }
84  
85 0 goto RETURN_MESSAGE;
86 }
87  
88 0 my $avail_time = $self->state_get($emerg_key);
89 0 ▶ if ($avail_time && time < $avail_time) {
Branch: 1 branch
BranchTrueFalseTotal
if ($avail_time and time < $avail_time) 0 0 0
Condition0%0/3
$avail_time and time < $avail_time
!ll&&!rl&&r
000
MC/DC0%0/2
$avail_time and time < $avail_time
$avail_time time < $avail_time
Truth table0%0/3
A and B
A= $avail_timeB= time < $avail_time
ABresult
0X0
100
111
90 0 return (); # drop message!
91 }
92  
93 0 ▶ if ( $qs->is_timed( $table ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qs->is_timed($table)) 0 0 0
94 # if this is from an emergency queue or a timed queue, we go ahead
95 # and allow the message, but we also update the throttler's count
96 # so the next message from a normal queue would be throttled correctly
97 0 ▶ if ($message->header(&Mvalve::Const::RETRY_HEADER)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($message->header(&Mvalve::Const::RETRY_HEADER)) 0 0 0
98 0 $self->state_decr( [ $destination, 'retry' ] );
99 }
100 0 $self->fill( key => $destination );
101  
102 # XXX - This is bad practive, but oh well
103 0 goto RETURN_MESSAGE;
104 }
105  
106 # otherwise, we need to check if this message is going to be throttled
107 0 my $is_pending = $self->is_pending( $destination );
108 0 my $is_throttled = ! $self->try_push( key => $destination );
109 0 ▶ Mvalve::trace( "checking if message to $destination should be throttled (pending: $is_pending, throttled: $is_throttled)" ) if &Mvalve::Const::MVALVE_TRACE;
Branch: 1 branch
BranchTrueFalseTotal
if &Mvalve::Const::MVALVE_TRACE 0 0 0
110  
111 0 ▶ if ($is_throttled || $is_pending) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_throttled or $is_pending) 0 0 0
Condition0%0/3
$is_throttled or $is_pending
l!l&&r!l&&!r
000
MC/DC0%0/2
$is_throttled or $is_pending
$is_throttled $is_pending
Truth table0%0/3
A or B
A= $is_throttledB= $is_pending
ABresult
1X1
011
000
112 0 ▶ Mvalve::trace( "message", $message->id, "is being throttled") if &Mvalve::Const::MVALVE_TRACE;
Branch: 1 branch
BranchTrueFalseTotal
if &Mvalve::Const::MVALVE_TRACE 0 0 0
113 0 $self->defer(
114 message => $message,
115 interval => $self->throttler->interval,
116 );
117 0 $self->log(
118 action => "throttle",
119 destination => $destination
120 );
121 0 return (); # no data for you!
122 }
123  
124 RETURN_MESSAGE:
125 # if we got here, we can just return the data
126 0 ▶ Mvalve::trace( "message", $message->id, "being returned") if &Mvalve::Const::MVALVE_TRACE;
Branch: 1 branch
BranchTrueFalseTotal
if &Mvalve::Const::MVALVE_TRACE 0 0 0
127 0 $self->log(
128 action => "dequeue",
129 destination => $destination,
130 );
131 0 return $message;
132 }
133  
134 0 ▶sub is_pending {
Subroutine is_pending: not called CC=2 SCAR=17.9
Pod documented
135 0 my( $self, $destination ) = @_;
136  
137 0 my $retry_key = [ $destination, 'retry' ];
138 0 my $count = $self->state_get($retry_key);
139 0 ▶ return $count ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$count ? : 0 0 0
140 }
141  
142 1 1;
143  
144 __END__
↑ Summary Mvalve/Base.pm »