| 1 | package Queue::Q::ReliableFIFO::Redis; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Carp qw(croak cluck); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use parent 'Queue::Q::ReliableFIFO'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Queue::Q::ReliableFIFO::Item; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Queue::Q::ReliableFIFO::Lua; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Redis; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Time::HiRes qw(usleep); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Class::XSAccessor { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | getters => [qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | server | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | port | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | db | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | queue_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | busy_expiry_time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | claim_wait_timeout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | requeue_limit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | redis_conn | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | redis_options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | warn_on_requeue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | _main_queue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | _busy_queue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | _failed_queue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | _time_queue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | _temp_queue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | _log_queue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | _script_cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | _lua | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | setters => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | set_requeue_limit => 'requeue_limit', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | set_busy_expiry_time => 'busy_expiry_time', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | set_claim_wait_timeout => 'claim_wait_timeout', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | my %QueueType = map { $_ => undef } (qw(main busy failed time temp log)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my ($class, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | for (qw(server port queue_name)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | croak("Need '$_' parameter") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if not defined $params{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my %AllowedNewParams = map { $_ => undef } (qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | server port db queue_name busy_expiry_time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | claim_wait_timeout requeue_limit redis_conn redis_options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | warn_on_requeue)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | for (keys %params) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | croak("Invalid parameter '$_'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if not exists $AllowedNewParams{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $self = bless({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | requeue_limit => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | busy_expiry_time => 30, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | claim_wait_timeout => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | db => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | warn_on_requeue => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | %params | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } => $class); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | $self->{"_$_" . '_queue'} = $params{queue_name} . "_$_" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | for keys %QueueType; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | $self->{redis_options} ||= { reconnect => 60 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"redis_options"} ||= {"reconnect", 60}
MC/DC0%0/1
$self->{"redis_options"} ||= {"reconnect", 60}
$self->{"redis_options"}
Truth table0%0/2
A
A= $self->{"redis_options"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | $self->{redis_conn} ||= Redis->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # by default, auto-reconnect during 60 seconds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | %{$self->{redis_options}}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"redis_conn"} ||= "Redis"->new(%{$$self{"redis_options"};}, "encoding", undef, "server", join(":", $self->server, $self->port))
MC/DC0%0/2
$self->{"redis_conn"} ||= "Redis"->new(%{$$self{"redis_options"};}, "encoding", undef, "server", join(":", $self->server, $self->port))
$self->{"redis_conn"}
"Redis"->new(%{$$self{"redis_options"};}, "encoding", undef, "server", join(":", $self->server, $self->port))
Truth table0%0/3
A ||= B
A= $self->{"redis_conn"}B= "Redis"->new(%{$$self{"redis_options"};}, "encoding", undef, "server", join(":", $self->server, $self->port))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | encoding => undef, # force undef for binary data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | server => join(":", $self->server, $self->port), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | $self->redis_conn->select($self->db) if $self->db; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | $self->{_lua} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | = Queue::Q::ReliableFIFO::Lua->new(redis_conn => $self->redis_conn); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub clone { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my ($class, $org, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my %default = map { $_ => $org->{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | grep m/^[a-zA-Z]/, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | keys %$org; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | return $class->new(%default, %params); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub enqueue_item { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enqueue_item: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | return if not @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | return $self->redis_conn->lpush( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | $self->_main_queue, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | map { Queue::Q::ReliableFIFO::Item->new(data => $_)->_serialized } @_ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | ▶ | use constant NONBLOCKING => 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | ▶ | use constant BLOCKING => 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub claim_item { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
claim_item: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my ($self, $n) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | return $self->_claim_item_internal($n, BLOCKING); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub claim_item_nonblocking { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
claim_item_nonblocking: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my ($self, $n) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return $self->_claim_item_internal($n, NONBLOCKING); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub _claim_item_internal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_claim_item_internal: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my ($self, $n, $doblocking) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | $n ||= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$n ||= 1
MC/DC0%0/1
$n ||= 1
$n
Truth table0%0/2
A
A= $n
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my $timeout = $self->claim_wait_timeout; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if ($n == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # rpoplpush gives higher throughput than the blocking version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # (i.e. brpoplpush). So use the blocked version only when we | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # need to wait. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $value = $self->redis_conn->rpoplpush($self->_main_queue, $self->_busy_queue); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if (not defined($value) and $doblocking == BLOCKING) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $value and $doblocking == 1
MC/DC0%0/2
not defined $value and $doblocking == 1
not defined $value
$doblocking == 1
Truth table0%0/3
not(A) and B
A= not defined $valueB= $doblocking == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $value = $self->redis_conn->brpoplpush($self->_main_queue, $self->_busy_queue, $timeout); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | return if not $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | eval { ($item) = Queue::Q::ReliableFIFO::Item->new(_serialized => $value); }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # FIXME ignoring exception in eval{}! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | return $item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my $conn = $self->redis_conn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my $qn = $self->_main_queue; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $bq = $self->_busy_queue; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my @items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | my $serial; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if ($n > 30) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # yes, there is a race, but it's an optimization only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my ($l) = $self->redis_conn->llen($qn); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | $n = $l if $l < $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | $conn->rpoplpush($qn, $bq, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | if (defined $_[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | push @items, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | Queue::Q::ReliableFIFO::Item->new(_serialized => $_[0]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | }) for 1..$n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $conn->wait_all_responses; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | if (@items == 0 && $doblocking == BLOCKING) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@items == 0 and $doblocking == 1
MC/DC0%0/2
@items == 0 and $doblocking == 1
@items == 0
$doblocking == 1
Truth table0%0/3
A and B
A= @items == 0B= $doblocking == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # list seems empty, use the blocking version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | $serial = $conn->brpoplpush($qn, $bq, $timeout); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if (defined $serial) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | push(@items, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | Queue::Q::ReliableFIFO::Item->new(_serialized => $serial)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | undef $serial; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | $conn->rpoplpush($qn, $bq, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | if (defined $_[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | push @items, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | Queue::Q::ReliableFIFO::Item->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | _serialized => $_[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | }) for 1 .. ($n-1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $conn->wait_all_responses; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | return @items; # return with whatever we have... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | return @items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | sub mark_item_as_done { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mark_item_as_done: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | return $self->redis_conn->lrem( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | $self->_busy_queue, -1, $_[0]->_serialized); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # TODO since lrem is an O(n) operation in size of busy list, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # there's a crossover point at which having l items to remove | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # from said list is better done in a single O(n) loop through | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # the list (in Lua?) rather than in l*O(n)=O(ln) operations via | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # _lrem! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my $conn = $self->redis_conn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | $conn->lrem( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | $self->_busy_queue, -1, $_->_serialized, sub { $count += $_[0] }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | for @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $conn->wait_all_responses; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | return $count; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | sub unclaim { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unclaim: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | return $self->__requeue_busy(1, undef, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | sub requeue_busy_item { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
requeue_busy_item: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my ($self, $raw) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | return $self->__requeue_busy(0, undef, $raw); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | sub requeue_busy { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
requeue_busy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | return $self->__requeue_busy(0, undef, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | sub requeue_busy_error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
requeue_busy_error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | my $error= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | return $self->__requeue_busy(0, $error, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | sub __requeue_busy { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__requeue_busy: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my $place = shift; # 0: producer side, 1: consumer side | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my $error = shift; # error message | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my $n = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | $n += $self->_lua->call( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 'requeue_busy', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | $self->_busy_queue, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | $self->_main_queue, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | $self->_failed_queue, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | time(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | $_->_serialized, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | $self->requeue_limit, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | $place, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | $error || '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | ) for @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$error || ''
MC/DC0%0/1
$error || ''
$error
Truth table0%0/2
A
A= $error
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | cluck("Lua call went wrong! $@"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | return $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | sub requeue_failed_item { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
requeue_failed_item: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # **deprecated *** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # This can stress Redis very hard when there are many failed items. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # The lrem operation does a scan. If the item is not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # at the position where the lrem-search start, the scan goes on. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # A sleep is added in case the method is called for multiple items. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | my $n = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | for (@_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | $n += $self->_lua->call( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 'requeue_failed_item', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | $self->_failed_queue, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | $self->_main_queue, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | time(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | $_->_serialized, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | usleep(1e5); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | cluck("Lua call went wrong! $@"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | return $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | sub requeue_failed_items { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
requeue_failed_items: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # old API | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | my $limit = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my $n = $self->_lua->call( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 'requeue_failed', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | $self->_failed_queue, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | $self->_main_queue, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | time(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | $limit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | if (!defined $n) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | cluck("Lua call went wrong! $@"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | return $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | my %options = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # delay: how long before trying again after a (temporary) fail | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | my $delay = delete $options{Delay} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $options{'Delay'} || 0
MC/DC0%0/1
delete $options{'Delay'} || 0
delete $options{'Delay'}
Truth table0%0/2
A
A= delete $options{'Delay'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | my $max_fc = delete $options{MaxFailCount} || -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $options{'MaxFailCount'} || -1
MC/DC0%0/1
delete $options{'MaxFailCount'} || -1
delete $options{'MaxFailCount'}
Truth table0%0/2
A
A= delete $options{'MaxFailCount'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | my $chunk = delete $options{Chunk} || 100; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $options{'Chunk'} || 100
MC/DC0%0/1
delete $options{'Chunk'} || 100
delete $options{'Chunk'}
Truth table0%0/2
A
A= delete $options{'Chunk'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | cluck("Invalid option: $_") for (keys %options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my $total_requeued = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | if ($self->queue_length('failed') > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | my ($todo, $requeued) = (0,0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ($todo, $requeued) = split(/\s+/, $self->_lua->call( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 'requeue_failed_gentle', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | $self->_failed_queue, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | $self->_main_queue, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | $self->_temp_queue, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | time(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | $chunk, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | $delay, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | $max_fc, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $total_requeued += $requeued; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | usleep(1e5); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | while($todo > 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | return $total_requeued; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | sub get_and_flush_failed_items { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_and_flush_failed_items: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | # depreacted, use remove_failed_items | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my ($self, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | my (undef, $failures) = $self->remove_failed_items(%options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | return @$failures; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | sub remove_failed_items { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove_failed_items: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | my ($self, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | my $min_age = delete $options{MinAge} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $options{'MinAge'} || 0
MC/DC0%0/1
delete $options{'MinAge'} || 0
delete $options{'MinAge'}
Truth table0%0/2
A
A= delete $options{'MinAge'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | my $min_fc = delete $options{MinFailCount} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $options{'MinFailCount'} || 0
MC/DC0%0/1
delete $options{'MinFailCount'} || 0
delete $options{'MinFailCount'}
Truth table0%0/2
A
A= delete $options{'MinFailCount'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | my $chunk = delete $options{Chunk} || 100; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $options{'Chunk'} || 100
MC/DC0%0/1
delete $options{'Chunk'} || 100
delete $options{'Chunk'}
Truth table0%0/2
A
A= delete $options{'Chunk'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | my $loglimit= delete $options{LogLimit} || 100; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $options{'LogLimit'} || 100
MC/DC0%0/1
delete $options{'LogLimit'} || 100
delete $options{'LogLimit'}
Truth table0%0/2
A
A= delete $options{'LogLimit'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | cluck("Invalid option: $_") for (keys %options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my $total_removed= 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | if ($self->queue_length('failed') > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | my ($todo, $removed) = (0,0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | my $now = time(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | ($todo, $removed) = split(/\s+/, $self->_lua->call( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 'remove_failed_gentle', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | $self->_failed_queue, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | $self->_temp_queue, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | $self->_log_queue, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | $now, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | $chunk, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | ($now - $min_age), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | $min_fc, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | $loglimit, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | $total_removed += $removed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | usleep(1e5); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | while($todo > 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | return (0,[]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | if $total_removed == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | my $conn = $self->redis_conn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | my @serial = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | map { Queue::Q::ReliableFIFO::Item->new(_serialized => $_) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | $conn->lrange($self->_log_queue, 0, -1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $conn->del($self->_log_queue); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | return ($total_removed, \@serial); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | sub flush_queue { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flush_queue: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | my $conn = $self->redis_conn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | $conn->multi; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | $conn->del($_) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | for ($self->_main_queue, $self->_busy_queue, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | $self->_failed_queue, $self->_time_queue); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | $conn->exec; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | sub queue_length { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
queue_length: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | my ($self, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | __validate_type(\$type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | my $qn = $self->queue_name . "_$type"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | my ($len) = $self->redis_conn->llen($qn); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | return $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | sub peek_item { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
peek_item: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | my ($self, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # this function returns the value of oldest item in the queue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | __validate_type(\$type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | my $qn = $self->queue_name . "_$type"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | # take oldest item | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | my ($serial) = $self->redis_conn->lrange($qn,-1,-1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | return undef if ! $serial; # empty queue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | my $item = Queue::Q::ReliableFIFO::Item->new(_serialized => $serial); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | return $item->data(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | sub age { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
age: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | my ($self, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # this function returns age of oldest item in the queue (in seconds) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | __validate_type(\$type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | my $qn = $self->queue_name . "_$type"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # take oldest item | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | my ($serial) = $self->redis_conn->lrange($qn,-1,-1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | ▶ | return 0 if ! $serial; # empty queue, so age 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | my $item = Queue::Q::ReliableFIFO::Item->new(_serialized => $serial); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | return time() - $item->time_queued; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | sub raw_items_main { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
raw_items_main: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | return $self->_raw_items('main', @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | sub raw_items_busy { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
raw_items_busy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | return $self->_raw_items('busy', @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | sub raw_items_failed { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
raw_items_failed: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | return $self->_raw_items('failed', @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | sub _raw_items { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_raw_items: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | my ($self, $type, $n) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | #__validate_type(\$type); # truism, cf. the ten lines above this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | $n ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$n ||= 0
MC/DC0%0/1
$n ||= 0
$n
Truth table0%0/2
A
A= $n
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | my $qn = $self->queue_name . "_$type"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | map { Queue::Q::ReliableFIFO::Item->new(_serialized => $_); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | $self->redis_conn->lrange($qn, -$n, -1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | sub __validate_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__validate_type: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | $$type ||= 'main'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$$type ||= "main"
MC/DC0%0/1
$$type ||= "main"
$$type
Truth table0%0/2
A
A= $$type
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | croak("Unknown queue type $$type") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | ▶ | if not exists $QueueType{$$type}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | sub memory_usage_perc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
memory_usage_perc: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | my $conn = $self->redis_conn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | my $info = $conn->info('memory'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | my $mem_used = $info->{used_memory}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | my (undef, $mem_avail) = $conn->config('get', 'maxmemory'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | ▶ | return 100 if $mem_avail == 0; # if nothing is available, it's full! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | return $mem_used * 100 / $mem_avail; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | SCOPE: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 1 | my %ValidErrorActions = map { $_ => 1 } (qw(drop requeue)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 1 | my %ValidOptions = map { $_ => 1 } (qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | Chunk DieOnError ReturnOnDie MaxItems MaxSeconds ProcessAll Pause ReturnWhenEmpty NoSigHandlers WarnOnError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | sub consume { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
consume: not called CC=92 SCAR=90.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | my ($self, $callback, $error_action, $options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | # validation of input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | ▶ | $error_action ||= 'requeue'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$error_action ||= "requeue"
MC/DC0%0/1
$error_action ||= "requeue"
$error_action
Truth table0%0/2
A
A= $error_action
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | croak("Unknown error action") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | if not exists $ValidErrorActions{$error_action}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | my %error_subs = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | 'drop' => sub { my ($self, $item) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | $self->mark_item_as_done($item); }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | 'requeue' => sub { my ($self, $item, $error) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | $self->requeue_busy_error($error, $item); }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | my $onerror = $error_subs{$error_action} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$error_subs{$error_action} || croak("no handler for $error_action")
MC/DC0%0/1
$error_subs{$error_action} || croak("no handler for $error_action")
$error_subs{$error_action}
Truth table0%0/2
A
A= $error_subs{$error_action}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | || croak("no handler for $error_action"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | ▶ | $options = $options ? {%$options} : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | my $chunk = delete $options->{Chunk} || 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $options->{'Chunk'} || 1
MC/DC0%0/1
delete $options->{'Chunk'} || 1
delete $options->{'Chunk'}
Truth table0%0/2
A
A= delete $options->{'Chunk'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | croak("Chunk should be a number > 0") if (! $chunk > 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | cluck("DieOnError is deprecated, use ReturnOnDie instead") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | if exists $options->{DieOnError}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | my $return = delete $options->{ReturnOnDie} || delete $options->{DieOnError} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
delete $options->{'ReturnOnDie'} || delete $options->{'DieOnError'} || 0
delete $options->{"ReturnOnDie"} or delete $options->{"DieOnError"}
MC/DC0%0/2
delete $options->{'ReturnOnDie'} || delete $options->{'DieOnError'} || 0
delete $options->{"ReturnOnDie"}
delete $options->{"DieOnError"}
Truth table0%0/3
A or B
A= delete $options->{"ReturnOnDie"}B= delete $options->{"DieOnError"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | my $maxitems = delete $options->{MaxItems} || -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $options->{'MaxItems'} || -1
MC/DC0%0/1
delete $options->{'MaxItems'} || -1
delete $options->{'MaxItems'}
Truth table0%0/2
A
A= delete $options->{'MaxItems'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | my $maxseconds = delete $options->{MaxSeconds} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $options->{'MaxSeconds'} || 0
MC/DC0%0/1
delete $options->{'MaxSeconds'} || 0
delete $options->{'MaxSeconds'}
Truth table0%0/2
A
A= delete $options->{'MaxSeconds'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | ▶ | my $pause = delete $options->{Pause} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $options->{'Pause'} || 0
MC/DC0%0/1
delete $options->{'Pause'} || 0
delete $options->{'Pause'}
Truth table0%0/2
A
A= delete $options->{'Pause'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | my $process_all = delete $options->{ProcessAll} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $options->{'ProcessAll'} || 0
MC/DC0%0/1
delete $options->{'ProcessAll'} || 0
delete $options->{'ProcessAll'}
Truth table0%0/2
A
A= delete $options->{'ProcessAll'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | my $return_when_empty= delete $options->{ReturnWhenEmpty} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $options->{'ReturnWhenEmpty'} || 0
MC/DC0%0/1
delete $options->{'ReturnWhenEmpty'} || 0
delete $options->{'ReturnWhenEmpty'}
Truth table0%0/2
A
A= delete $options->{'ReturnWhenEmpty'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | ▶ | my $nohandlers = delete $options->{NoSigHandlers} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $options->{'NoSigHandlers'} || 0
MC/DC0%0/1
delete $options->{'NoSigHandlers'} || 0
delete $options->{'NoSigHandlers'}
Truth table0%0/2
A
A= delete $options->{'NoSigHandlers'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | my $warn_on_error = delete $options->{WarnOnError} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $options->{'WarnOnError'} || 0
MC/DC0%0/1
delete $options->{'WarnOnError'} || 0
delete $options->{'WarnOnError'}
Truth table0%0/2
A
A= delete $options->{'WarnOnError'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | croak("Option ProcessAll without Chunk does not make sense") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$process_all and $chunk <= 1
MC/DC0%0/2
$process_all and $chunk <= 1
$process_all
$chunk <= 1
Truth table0%0/3
A and B
A= $process_allB= $chunk <= 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | if $process_all && $chunk <= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | croak("Option Pause without Chunk does not make sense") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$pause and $chunk <= 1
MC/DC0%0/2
$pause and $chunk <= 1
$pause
$chunk <= 1
Truth table0%0/3
A and B
A= $pauseB= $chunk <= 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | if $pause && $chunk <= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | for (keys %$options) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | croak("Unknown option $_") if not exists $ValidOptions{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | ▶ | my $stop_time = $maxseconds > 0 ? time() + $maxseconds : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | # Now we can start... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | my $stop = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | my $MAX_RECONNECT = 60; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | my $sigint = ref $SIG{INT} eq 'CODE' ? $SIG{INT} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | my $sigterm = ref $SIG{TERM} eq 'CODE' ? $SIG{TERM} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | ▶ | local $SIG{INT} = $nohandlers ? $sigint : sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | print "stopping\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | $stop = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | &$sigint if $sigint; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | ▶ | local $SIG{TERM} = $nohandlers ? $sigterm : sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | print "stopping\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | $stop = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | &$sigterm if $sigterm; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | ▶ | if ($chunk == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | my $die_afterwards = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | my $claimed_count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | my $done_count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | while(!$stop) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | my $item = eval { $self->claim_item(); }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | ▶ | if (!$item) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | ▶ | last if $return_when_empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$return_when_empty or $stop_time > 0 and time >= $stop_time
$stop_time > 0 and time >= $stop_time
MC/DC0%0/3
$return_when_empty or $stop_time > 0 and time >= $stop_time
$return_when_empty
$stop_time > 0
time >= $stop_time
Truth table0%0/4
A or B and C
A= $return_when_emptyB= $stop_time > 0C= time >= $stop_time
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | || ($stop_time > 0 && time() >= $stop_time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | next; # nothing claimed this time, try again | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | $claimed_count++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | my $ok = eval { $callback->($item->data); 1; }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | my $error = _clean_error($@); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | warn "callback had an error: $error" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$warn_on_error and $error
MC/DC0%0/2
$warn_on_error and $error
$warn_on_error
$error
Truth table0%0/3
A and B
A= $warn_on_errorB= $error
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | if $warn_on_error and $error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | for (1 .. $MAX_RECONNECT) { # retry if connection is lost | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | eval { $onerror->($self, $item, $error); 1; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | last if $stop; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | ▶ | if ($return) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | $stop = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | cluck("Stopping because of ReturnOnDie\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | for (1 .. $MAX_RECONNECT) { # retry if connection is lost | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | $done_count += $self->mark_item_as_done($item); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | ▶ | last if $stop; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | ▶ | $stop = 1 if ($maxitems > 0 && --$maxitems == 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$maxitems > 0 and --$maxitems == 0 or $stop_time > 0 and time >= $stop_time
$maxitems > 0 and --$maxitems == 0
$stop_time > 0 and time >= $stop_time
MC/DC0%0/4
$maxitems > 0 and --$maxitems == 0 or $stop_time > 0 and time >= $stop_time
$maxitems > 0
--$maxitems == 0
$stop_time > 0
time >= $stop_time
Truth table0%0/7
A and B or C and D
A= $maxitems > 0B= --$maxitems == 0C= $stop_time > 0D= time >= $stop_time
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | || ($stop_time > 0 && time() >= $stop_time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | my $still_busy = $claimed_count - $done_count; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | ▶ | warn "not all items removed from busy queue ($still_busy)\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->warn_on_requeue and $still_busy
MC/DC0%0/2
$self->warn_on_requeue and $still_busy
$self->warn_on_requeue
$still_busy
Truth table0%0/3
A and B
A= $self->warn_on_requeueB= $still_busy
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | if $self->warn_on_requeue && $still_busy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | my $die_afterwards = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | my $t0 = Time::HiRes::time(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | ▶ | while(!$stop) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | my @items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | # give queue some time to grow | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | ▶ | if ($pause) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | my $pt = ($pause - (Time::HiRes::time()-$t0))*1e6; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | ▶ | Time::HiRes::usleep($pt) if $pt > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | eval { @items = $self->claim_item($chunk); 1; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | print "error with claim\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | ▶ | $t0 = Time::HiRes::time() if $pause; # only relevant for pause | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | ▶ | if (@items == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | ▶ | last if $return_when_empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$return_when_empty or $stop_time > 0 and time >= $stop_time
$stop_time > 0 and time >= $stop_time
MC/DC0%0/3
$return_when_empty or $stop_time > 0 and time >= $stop_time
$return_when_empty
$stop_time > 0
time >= $stop_time
Truth table0%0/4
A or B and C
A= $return_when_emptyB= $stop_time > 0C= time >= $stop_time
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | || ($stop_time > 0 && time() >= $stop_time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | next; # nothing claimed this time, try again | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | my @done; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | ▶ | if ($process_all) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | # process all items in one call (option ProcessAll) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | my $ok = eval { $callback->(map { $_->data } @items); 1; }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | ▶ | if ($ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | @done = splice @items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | # we need to call onerror for all items now | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | @done = (); # consider all items failed | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | my $error = _clean_error($@); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | ▶ | warn "callback had an error: $error" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$warn_on_error and $error
MC/DC0%0/2
$warn_on_error and $error
$warn_on_error
$error
Truth table0%0/3
A and B
A= $warn_on_errorB= $error
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | if $warn_on_error and $error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | ▶ | while (my $item = shift @items) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | for (1 .. $MAX_RECONNECT) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | eval { $onerror->($self, $item, $error); 1; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | ▶ | last if $stop; # items might stay in busy mode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | ▶ | if ($return) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | cluck("Stopping because of ReturnOnDie\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | $stop = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | last if $stop; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | # normal case: process items one by one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | ▶ | while (my $item = shift @items) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | my $ok = eval { $callback->($item->data); 1; }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | ▶ | if ($ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | push @done, $item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | my $error = _clean_error($@); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | warn "callback had an error: $error" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$warn_on_error and $error
MC/DC0%0/2
$warn_on_error and $error
$warn_on_error
$error
Truth table0%0/3
A and B
A= $warn_on_errorB= $error
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | if $warn_on_error and $error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | # retry if connection is lost | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | for (1 .. $MAX_RECONNECT) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | eval { $onerror->($self, $item, $error); 1; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | ▶ | last if $stop; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | ▶ | if ($return) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | cluck("Stopping because of ReturnOnDie\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | $stop = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | ▶ | last if $stop; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | for (1 .. $MAX_RECONNECT) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | eval { $count += $self->mark_item_as_done(@done); 1; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | ▶ | last if $stop; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | ▶ | warn "not all items removed from busy queue ($count)\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->warn_on_requeue and $count != @done
MC/DC0%0/2
$self->warn_on_requeue and $count != @done
$self->warn_on_requeue
$count != @done
Truth table0%0/3
A and B
A= $self->warn_on_requeueB= $count != @done
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | if $self->warn_on_requeue && $count != @done; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | # put back the claimed but not touched items | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | ▶ | if (@items > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | my $n = @items; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | print "unclaiming $n items\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | for (1 .. $MAX_RECONNECT) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | eval { $self->unclaim($_) for @items; 1; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | ▶ | or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | ▶ | last if $stop; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | sleep 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | ▶ | $stop = 1 if ($maxitems > 0 && ($maxitems -= @done) <= 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$maxitems > 0 and ($maxitems -= @done) <= 0 or $stop_time > 0 and time >= $stop_time
$maxitems > 0 and ($maxitems -= @done) <= 0
$stop_time > 0 and time >= $stop_time
MC/DC0%0/4
$maxitems > 0 and ($maxitems -= @done) <= 0 or $stop_time > 0 and time >= $stop_time
$maxitems > 0
($maxitems -= @done) <= 0
$stop_time > 0
time >= $stop_time
Truth table0%0/7
A and B or C and D
A= $maxitems > 0B= ($maxitems -= @done) <= 0C= $stop_time > 0D= time >= $stop_time
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | || ($stop_time > 0 && time() >= $stop_time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | } # end 'sub consume' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | } # end SCOPE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 1 | ▶ | sub _clean_error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_clean_error: not called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | $_[0] =~ s/, <GEN0> line [0-9]+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | chomp $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | return $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | # methods to be used for cleanup script and Nagios checks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | # the methods read or remove items from the busy queue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | ▶ | sub handle_expired_items { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_expired_items: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | my ($self, $timeout, $action) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | ▶ | $timeout ||= 10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$timeout ||= 10
MC/DC0%0/1
$timeout ||= 10
$timeout
Truth table0%0/2
A
A= $timeout
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | ▶ | die "timeout should be a number> 0" if not int($timeout); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 0 | ▶ | die "unknown action" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$action and $action =~ /^(?:requeue|drop)$/
MC/DC0%0/2
$action and $action =~ /^(?:requeue|drop)$/
$action
$action =~ /^(?:requeue|drop)$/
Truth table0%0/3
A and B
A= $actionB= $action =~ /^(?:requeue|drop)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | if not $action or $action !~ /^(?:requeue|drop)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | my $conn = $self->redis_conn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | my @serial = $conn->lrange($self->_busy_queue, 0, -1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | my $time = time; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | my %timetable = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | map { reverse split /-/,$_,2 } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | $conn->lrange($self->_time_queue, 0, -1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | my @match = grep { exists $timetable{$_} } @serial; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | my %match = map { $_ => undef } @match; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | my @timedout = grep { $time - $timetable{$_} >= $timeout } @match; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | my @log; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | ▶ | if ($action eq 'requeue') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | for my $serial (@timedout) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | my $item = Queue::Q::ReliableFIFO::Item->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | _serialized => $serial | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | my $n = $self->requeue_busy_item($item); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | ▶ | push @log, $item | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | if $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | elsif ($action eq 'drop') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | for my $serial (@timedout) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | my $n = $conn->lrem( $self->_busy_queue, -1, $serial); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | ▶ | push @log, Queue::Q::ReliableFIFO::Item->new(_serialized => $serial) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | if $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | # We create a new timetable. We take the original timetable and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | # exclude: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | # 1. the busy items which timed out and we just handled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | # 2. timetable items which have no corresponding busy items anymore | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | my %timedout = map { $_ => undef } @timedout; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 0 | my %busy = map { $_ => undef } @serial; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | my %newtimetable = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 0 | map { $_ => $timetable{$_} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | grep { exists $busy{$_} } # exclude (ad 2.) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 0 | grep { ! exists $timedout{$_} } # exclude (ad 1.) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | keys %timetable; # original timetable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | # put in the items of latest scan we did not see before | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | $newtimetable{$_} = $time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | for (grep { !exists $newtimetable{$_} } @serial); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 0 | $conn->multi; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | $conn->del($self->_time_queue); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | $conn->lpush($self->_time_queue, join('-',$newtimetable{$_},$_)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 0 | for (keys %newtimetable); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | $conn->exec; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | #FIXME the log info should also show what is done with the items | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | # (e.g. dropped after requeue limit). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | return @log; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||