| 1 | package Tapper::MCP::Scheduler::Queue; | ||||||||||
| 2 | 21 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||
| 3 | 21 | $Tapper::MCP::Scheduler::Queue::VERSION = '5.0.9'; | |||||||||
| 4 | 21 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 21 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 21 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 21 | ▶ | use MooseX::ClassAttribute; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 21 | ▶ | use Tapper::Model 'model'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 21 | ▶ | use Tapper::MCP::Scheduler::ObjectBuilder; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 21 | ▶ | use Scalar::Util qw/weaken/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 21 | ▶ | use Perl6::Junction qw/any/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | 21 | has id => (is => 'ro'); | |||||||||
| 16 | 21 | has name => (is => 'ro'); | |||||||||
| 17 | 21 | has priority => (is => 'ro'); | |||||||||
| 18 | 21 | has runcount => (is => 'rw'); | |||||||||
| 19 | 21 | has active => (is => 'ro'); | |||||||||
| 20 | 21 | has is_deleted => (is => 'ro'); | |||||||||
| 21 | 21 | has created_at => (is => 'ro'); | |||||||||
| 22 | 21 | has updated_at => (is => 'ro'); | |||||||||
| 23 | has testrunschedulings => (is => 'ro', | ||||||||||
| 24 | lazy => 1, | ||||||||||
| 25 | 107 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 26 | 107 | my ($self) = shift; | |||||||||
| 27 | 107 | my @return_jobs; | |||||||||
| 28 | 107 | my $jobs = model('TestrunDB')->resultset('TestrunScheduling')->search({queue_id => $self->id, status => 'schedule'}); | |||||||||
| 29 | 107 | $jobs->result_class('DBIx::Class::ResultClass::HashRefInflator'); | |||||||||
| 30 | 107 | my $obj_builder = Tapper::MCP::Scheduler::ObjectBuilder->instance; | |||||||||
| 31 | |||||||||||
| 32 | 107 | ▶ | while (my $this_job = $jobs->next) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 110 | $this_job->{queue} = $self; | |||||||||
| 34 | 110 | push @return_jobs, $obj_builder->new_job(%{$this_job}); | |||||||||
| 35 | 110 | weaken $return_jobs[$#return_jobs]; | |||||||||
| 36 | } | ||||||||||
| 37 | 107 | return \@return_jobs; | |||||||||
| 38 | 21 | }); | |||||||||
| 39 | has queuehosts => (is => 'ro', | ||||||||||
| 40 | lazy => 1, | ||||||||||
| 41 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 42 | 0 | my ($self) = shift; | |||||||||
| 43 | 0 | my @return_hosts; | |||||||||
| 44 | 0 | my $queue_hosts = model('TestrunDB')->resultset('QueueHost')->search({queue_id => $self->id}); | |||||||||
| 45 | 0 | my $obj_builder = Tapper::MCP::Scheduler::ObjectBuilder->instance; | |||||||||
| 46 | |||||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | while (my $this_qh = $queue_hosts->next) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 0 | my $hosts = model->resultset('Host')->search({id => $this_qh->host->id},{result_class => 'DBIx::Class::ResultClass::HashRefInflator'}); | |||||||||
| 50 | 0 | push @return_hosts, $obj_builder->new_host(%{$hosts->search({}, {rows => 1})->first}); | |||||||||
| 51 | 0 | weaken $return_hosts[$#return_hosts]; | |||||||||
| 52 | |||||||||||
| 53 | } | ||||||||||
| 54 | 0 | return \@return_hosts; | |||||||||
| 55 | 21 | }); | |||||||||
| 56 | has deniedhosts => (is => 'ro', | ||||||||||
| 57 | lazy => 1, | ||||||||||
| 58 | 107 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 59 | 107 | my ($self) = shift; | |||||||||
| 60 | 107 | my @return_hosts; | |||||||||
| 61 | 107 | my $queue_hosts = model('TestrunDB')->resultset('DeniedHost')->search({queue_id => $self->id}); | |||||||||
| 62 | 107 | my $obj_builder = Tapper::MCP::Scheduler::ObjectBuilder->instance; | |||||||||
| 63 | |||||||||||
| 64 | |||||||||||
| 65 | 107 | ▶ | while (my $this_qh = $queue_hosts->next) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 1 | my $hosts = model->resultset('Host')->search({id => $this_qh->host->id},{result_class => 'DBIx::Class::ResultClass::HashRefInflator'}); | |||||||||
| 67 | 1 | push @return_hosts, $obj_builder->new_host(%{$hosts->search({}, {rows => 1})->first}); | |||||||||
| 68 | 1 | weaken $return_hosts[$#return_hosts]; | |||||||||
| 69 | |||||||||||
| 70 | } | ||||||||||
| 71 | 107 | return \@return_hosts; | |||||||||
| 72 | }, | ||||||||||
| 73 | 21 | ); | |||||||||
| 74 | |||||||||||
| 75 | |||||||||||
| 76 | sub jobs | ||||||||||
| 77 | 80 | ▶ | { | ||||||||
|
Subroutine
jobs: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 78 | 80 | my $self = shift; | |||||||||
| 79 | 80 | return $self->testrunschedulings; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | sub get_first_fitting | ||||||||||
| 83 | 107 | ▶ | { | ||||||||
|
Subroutine
get_first_fitting: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||
| 84 | 107 | my ($self, $free_hosts, $available_resources) = @_; | |||||||||
| 85 | 107 | ▶ | $available_resources = [] unless defined $available_resources; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | |||||||||||
| 87 | 107 | my @forbidden_host_names; | |||||||||
| 88 | 107 | @forbidden_host_names = map {$_->name} @{$self->deniedhosts}; | |||||||||
| 89 | |||||||||||
| 90 | # "x ne any(x,y)" is not the same as "not x eq any(x,y)". That migt be confusing, so please keep the "not eq". | ||||||||||
| 91 | 107 | my @new_free_hosts = grep((not $_->{host}->name eq any(@forbidden_host_names)), @$free_hosts); | |||||||||
| 92 | 107 | $free_hosts = \@new_free_hosts; | |||||||||
| 93 | |||||||||||
| 94 | |||||||||||
| 95 | 107 | foreach my $job (@{$self->testrunschedulings}) { | |||||||||
| 96 | 80 | my $host = $job->fits($free_hosts); | |||||||||
| 97 | 80 | ▶ | next unless $host; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | |||||||||||
| 99 | # Check for unfinished dependencies | ||||||||||
| 100 | 27 | ▶ | next unless $job->dependencies_finished; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | |||||||||||
| 102 | # Reserves resources, must run if $resources_available is 1 | ||||||||||
| 103 | 27 | my ($resources_available,$acquireable_resources) = | |||||||||
| 104 | $job->claim_resources($available_resources); | ||||||||||
| 105 | 27 | ▶ | next unless $resources_available; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | |||||||||||
| 107 | 27 | my $db_job = model('TestrunDB')->resultset('TestrunScheduling')->find($job->{id}); | |||||||||
| 108 | 27 | $db_job->host_id ($host->id); | |||||||||
| 109 | |||||||||||
| 110 | 27 | ▶ | if ($db_job->testrun->scenario_element) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | 1 | $db_job->testrun->scenario_element->is_fitted(1); | |||||||||
| 112 | 1 | $db_job->testrun->scenario_element->update(); | |||||||||
| 113 | } | ||||||||||
| 114 | |||||||||||
| 115 | 27 | $db_job->update; | |||||||||
| 116 | |||||||||||
| 117 | 27 | return $db_job; | |||||||||
| 118 | } | ||||||||||
| 119 | 80 | return; | |||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | 21 | __PACKAGE__->meta->make_immutable; | |||||||||
| 123 | |||||||||||
| 124 | 21 | 1; | |||||||||
| 125 | |||||||||||
| 126 | __END__ | ||||||||||