| 1 | # $Id$ | ||||||||||||
| 2 | |||||||||||||
| 3 | package Mvalve::QueueSet; | ||||||||||||
| 4 | 1 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 1 | ▶ | use Time::HiRes(); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | has 'emergency_queues' => ( | ||||||||||||
| 8 | is => 'rw', | ||||||||||||
| 9 | isa => 'ArrayRef[HashRef]', | ||||||||||||
| 10 | auto_deref => 1, | ||||||||||||
| 11 | 0 | ▶ | default => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 12 | +[ | ||||||||||||
| 13 | { | ||||||||||||
| 14 | 0 | table => 'q_emerg' | |||||||||||
| 15 | }, | ||||||||||||
| 16 | ] | ||||||||||||
| 17 | } | ||||||||||||
| 18 | 1 | ); | |||||||||||
| 19 | |||||||||||||
| 20 | has 'timed_queues' => ( | ||||||||||||
| 21 | is => 'rw', | ||||||||||||
| 22 | isa => 'ArrayRef[HashRef]', | ||||||||||||
| 23 | auto_deref => 1, | ||||||||||||
| 24 | 0 | ▶ | default => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 25 | +[ | ||||||||||||
| 26 | { | ||||||||||||
| 27 | 0 | table => 'q_timed' | |||||||||||
| 28 | }, | ||||||||||||
| 29 | ] | ||||||||||||
| 30 | } | ||||||||||||
| 31 | 1 | ); | |||||||||||
| 32 | |||||||||||||
| 33 | has 'normal_queues' => ( | ||||||||||||
| 34 | is => 'rw', | ||||||||||||
| 35 | isa => 'ArrayRef[HashRef]', | ||||||||||||
| 36 | auto_deref => 1, | ||||||||||||
| 37 | 0 | ▶ | default => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 38 | +[ | ||||||||||||
| 39 | { | ||||||||||||
| 40 | 0 | table => 'q_incoming' | |||||||||||
| 41 | }, | ||||||||||||
| 42 | ] | ||||||||||||
| 43 | }, | ||||||||||||
| 44 | 1 | ); | |||||||||||
| 45 | |||||||||||||
| 46 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 47 | |||||||||||||
| 48 | 1 | ▶ | no Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 49 | |||||||||||||
| 50 | # Retry queue is not counted, as it's special | ||||||||||||
| 51 | sub all_queues | ||||||||||||
| 52 | 0 | ▶ | { | ||||||||||
|
Subroutine
all_queues: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 53 | 0 | my $self = shift; | |||||||||||
| 54 | |||||||||||||
| 55 | 0 | my @list = ( | |||||||||||
| 56 | $self->emergency_queues, | ||||||||||||
| 57 | $self->timed_queues, | ||||||||||||
| 58 | $self->normal_queues, | ||||||||||||
| 59 | ); | ||||||||||||
| 60 | 0 | ▶ | return wantarray ? @list : \@list; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | 0 | ▶ | sub all_tables { map { $_->{table} } ($_[0]->all_queues) } | ||||||||||
|
Subroutine
all_tables: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 64 | |||||||||||||
| 65 | 0 | ▶ | sub choose_table { | ||||||||||
|
Subroutine
choose_table: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 66 | 0 | my ($self, $type) = @_; | |||||||||||
| 67 | 0 | ▶ | $type ||= 'normal'; | ||||||||||
|
Condition0%0/2
$type ||= "normal"
MC/DC0%0/1
$type ||= "normal"
$type
Truth table0%0/2
A
A= $type
| |||||||||||||
| 68 | |||||||||||||
| 69 | 0 | my $method = join('_', $type, 'queues'); | |||||||||||
| 70 | 0 | my @queues = $self->$method; | |||||||||||
| 71 | |||||||||||||
| 72 | 0 | return $queues[ rand(@queues) ]->{table}; | |||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | sub as_q4m_args | ||||||||||||
| 76 | 0 | ▶ | { | ||||||||||
|
Subroutine
as_q4m_args: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 77 | 0 | my $self = shift; | |||||||||||
| 78 | 0 | my $now = Time::HiRes::time() * 100000; | |||||||||||
| 79 | my @list = ( | ||||||||||||
| 80 | 0 | (map { $_->{table} } $self->emergency_queues), | |||||||||||
| 81 | 0 | (map { "$_->{table}:ready<" . $now } $self->timed_queues), | |||||||||||
| 82 | 0 | (map { $_->{table} } $self->normal_queues), | |||||||||||
| 83 | ); | ||||||||||||
| 84 | |||||||||||||
| 85 | 0 | ▶ | return wantarray ? @list : \@list; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 86 | } | ||||||||||||
| 87 | |||||||||||||
| 88 | sub is_emergency | ||||||||||||
| 89 | 0 | ▶ | { | ||||||||||
|
Subroutine
is_emergency: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 90 | 0 | my ($self, $table) = @_; | |||||||||||
| 91 | 0 | foreach my $q ($self->emergency_queues) { | |||||||||||
| 92 | 0 | ▶ | if ($q->{table} eq $table) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 93 | 0 | return 1; | |||||||||||
| 94 | } | ||||||||||||
| 95 | } | ||||||||||||
| 96 | 0 | return 0; | |||||||||||
| 97 | } | ||||||||||||
| 98 | |||||||||||||
| 99 | sub is_timed | ||||||||||||
| 100 | 0 | ▶ | { | ||||||||||
|
Subroutine
is_timed: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 101 | 0 | my ($self, $table) = @_; | |||||||||||
| 102 | 0 | foreach my $q ($self->timed_queues) { | |||||||||||
| 103 | 0 | ▶ | if ($q->{table} eq $table) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 104 | 0 | return 1; | |||||||||||
| 105 | } | ||||||||||||
| 106 | } | ||||||||||||
| 107 | 0 | return 0; | |||||||||||
| 108 | } | ||||||||||||
| 109 | |||||||||||||
| 110 | 1 | 1; | |||||||||||
| 111 | |||||||||||||
| 112 | __END__ | ||||||||||||