| 1 | package App::Prove::Elasticsearch::Queue::Rabbit; | ||||||||||||||||||||||||||||
| 2 | 1 | $App::Prove::Elasticsearch::Queue::Rabbit::VERSION = '0.001'; | |||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | # PODNAME: App::Prove::Elasticsearch::Queue::Rabbit; | ||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Coordinate the running of test plans across multiple instances via RabbitMQ. | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use parent qw{App::Prove::Elasticsearch::Queue::Default}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Net::RabbitMQ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use JSON::MaybeXS; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 0 | my ($class, $input) = @_; | |||||||||||||||||||||||||||
| 17 | 0 | my $self = $class->SUPER::new($input); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | #Connect to rabbit | ||||||||||||||||||||||||||||
| 20 | 0 | $self->{mq} = Net::RabbitMQ->new(); | |||||||||||||||||||||||||||
| 21 | 0 | ▶ | $self->{config}->{'queue.exchange'} ||= 'testsuite'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"config"}{"queue.exchange"} ||= "testsuite"
MC/DC0%0/1
$self->{"config"}{"queue.exchange"} ||= "testsuite"
$self->{"config"}{"queue.exchange"}
Truth table0%0/2
A
A= $self->{"config"}{"queue.exchange"}
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | #Allow callers to overwrite this to prevent double-usage of channels | ||||||||||||||||||||||||||||
| 24 | 0 | $self->{write_channel} = 1; | |||||||||||||||||||||||||||
| 25 | 0 | $self->{read_channel} = 2; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | my $port = | ||||||||||||||||||||||||||||
| 28 | $self->{config}->{'queue.port'} | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | ? ':' . $self->{config}->{'queue.port'} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | : ''; | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | die("queue.host must be specified") unless $self->{config}->{'queue.host'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 0 | my $serveraddress = "$self->{config}->{'queue.host'}$port"; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | $self->{mq}->connect( | ||||||||||||||||||||||||||||
| 35 | $serveraddress, | ||||||||||||||||||||||||||||
| 36 | { | ||||||||||||||||||||||||||||
| 37 | user => $self->{config}->{'queue.user'}, | ||||||||||||||||||||||||||||
| 38 | 0 | password => $self->{config}->{'queue.password'} | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | return $self; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub queue_jobs { | ||||||||||||||||||||||||||
|
Subroutine
queue_jobs: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 0 | my ($self, @jobs_to_queue) = @_; | |||||||||||||||||||||||||||
| 47 | 0 | $self->{mq}->channel_open($self->{write_channel}); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | my $options = | ||||||||||||||||||||||||||||
| 50 | $self->{config}->{'queue.exchange'} | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | ? {exchange => $self->{config}->{'queue.exchange'}} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | : undef; | ||||||||||||||||||||||||||||
| 53 | 0 | foreach my $job (@jobs_to_queue) { | |||||||||||||||||||||||||||
| 54 | 0 | $job->{queue_name} = $self->build_queue_name($job); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | #Publish each plan to it's own queue, and the name of this queue that needs work to the 'queues needing work' queue | ||||||||||||||||||||||||||||
| 57 | $self->{mq}->exchange_declare( | ||||||||||||||||||||||||||||
| 58 | $self->{write_channel}, | ||||||||||||||||||||||||||||
| 59 | 0 | $self->{config}->{'queue.exchange'}, {auto_delete => 0,} | |||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | $self->{mq}->queue_declare( | ||||||||||||||||||||||||||||
| 62 | $self->{write_channel}, $job->{queue_name}, | ||||||||||||||||||||||||||||
| 63 | 0 | {auto_delete => 0} | |||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||
| 65 | $self->{mq}->queue_bind( | ||||||||||||||||||||||||||||
| 66 | $self->{write_channel}, $job->{queue_name}, | ||||||||||||||||||||||||||||
| 67 | $self->{config}->{'queue.exchange'}, $job->{queue_name} | ||||||||||||||||||||||||||||
| 68 | 0 | ); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | #queue a test to a queue for the same version/platform/etc | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | @{$job->{tests}} = | |||||||||||||||||||||||||||
| 73 | 0 | &{\&{$self->{planner} . "::find_test_paths"}}(@{$job->{tests}}); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | #filter jobs by what is already done if this is a re-queue for optimization's sake | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ($self->{requeue}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 0 | $self->{searcher} = $self->_get_searcher(); | |||||||||||||||||||||||||||
| 78 | 0 | @{$job->{tests}} = $self->{searcher}->filter(@{$job->{tests}}); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | foreach my $test (@{$job->{tests}}) { | |||||||||||||||||||||||||||
| 82 | $self->{mq}->publish( | ||||||||||||||||||||||||||||
| 83 | 0 | $self->{write_channel}, $job->{queue_name}, $test, | |||||||||||||||||||||||||||
| 84 | $options | ||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | #Clients that wish to re-build to suit other jobs will have to query ES as to what other types of plans are available | ||||||||||||||||||||||||||||
| 89 | #This will result in the occasional situation where we rebuild, but work for the new queue has been exhausted by the time the worker gets there. | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | 0 | $self->{mq}->channel_close($self->{write_channel}); | |||||||||||||||||||||||||||
| 92 | 0 | $self->{mq}->disconnect(); | |||||||||||||||||||||||||||
| 93 | 0 | return 0; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub get_jobs { | ||||||||||||||||||||||||||
|
Subroutine
get_jobs: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 0 | my ($self, $jobspec) = @_; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | $self->{mq}->channel_open($self->{read_channel}); | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | #I don't think I will have to check that the platform is right & reject/requeue thanks to using multiple queues. | ||||||||||||||||||||||||||||
| 102 | 0 | my ($ctr, $job, @jobs) = (-1); | |||||||||||||||||||||||||||
| 103 | 0 | ▶ | while ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | $job = $self->{mq}->get( | ||||||||||||||||||||||||||||
| 105 | $self->{read_channel}, $jobspec->{queue_name}, | ||||||||||||||||||||||||||||
| 106 | {exchange => $self->{config}->{'queue.exchange'}} | ||||||||||||||||||||||||||||
| 107 | ) | ||||||||||||||||||||||||||||
| 108 | ) { | ||||||||||||||||||||||||||||
| 109 | 0 | $ctr++; | |||||||||||||||||||||||||||
| 110 | last | ||||||||||||||||||||||||||||
| 111 | if $self->{config}->{'queue.granularity'} | ||||||||||||||||||||||||||||
| 112 | 0 | ▶ | && $ctr >= $self->{config}->{'queue.granularity'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"config"}{"queue.granularity"} and $ctr >= $self->{"config"}{"queue.granularity"}
MC/DC0%0/2
$self->{"config"}{"queue.granularity"} and $ctr >= $self->{"config"}{"queue.granularity"}
$self->{"config"}{"queue.granularity"}
$ctr >= $self->{"config"}{"queue.granularity"}
Truth table0%0/3
A and B
A= $self->{"config"}{"queue.granularity"}B= $ctr >= $self->{"config"}{"queue.granularity"}
| |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | push(@jobs, $job->{body}) if $job->{body}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 0 | $self->{mq}->channel_close($self->{read_channel}); | |||||||||||||||||||||||||||
| 116 | 0 | $self->{mq}->disconnect(); | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | return @jobs; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 1 | 1; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | __END__ | ||||||||||||||||||||||||||||