MCP/Scheduler/PrioQueue.pm

filter: Statementstmt 100% 53 / 53 Branchbran 58.3% 7 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 86.2% 69 / 80 CC 9 SCAR 12.5
CC
9
Cov
90%
get_first_fitting
6.2
_max_seq
3.3
__ANON__
2.0
CRAP 3.5
« MCP/Scheduler/Queue.pm ↑ Summary MCP/Info.pm »
1 # critic (RequireUseStrict)
2 package Tapper::MCP::Scheduler::PrioQueue;
3 16 our $AUTHORITY = 'cpan:TAPPER';
4 # ABSTRACT: Object for test queue abstraction
5 16 $Tapper::MCP::Scheduler::PrioQueue::VERSION = '5.0.9';
6 16 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 16 ▶use Tapper::Model 'model';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use aliased 'Tapper::Schema::TestrunDB::Result::TestrunScheduling';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 has testrunschedulings => (is => 'ro',
14 lazy => 1,
15 46 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
16 46 my ($self) = shift;
17 46 my @return_jobs;
18 46 my $jobs = model('TestrunDB')->resultset('TestrunScheduling')->search({prioqueue_seq => { '>', 0}, status => 'schedule'}, {order_by => 'prioqueue_seq'});
19 46 $jobs->result_class('DBIx::Class::ResultClass::HashRefInflator');
20 46 my $obj_builder = Tapper::MCP::Scheduler::ObjectBuilder->instance;
21  
22 46 ▶ while (my $this_job = $jobs->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $this_job = $jobs->next) 1 46 47
23 1 $this_job->{queue} = $self;
24 1 push @return_jobs, $obj_builder->new_job(%{$this_job});
25 }
26 46 return \@return_jobs;
27 16 });
28  
29  
30 1 ▶sub _max_seq {
Subroutine _max_seq: called CC=3 SCAR=12.0
31 1 my ($self) = @_;
32  
33 1 my $job_with_max_seq = model('TestrunDB')->resultset('TestrunScheduling')->search
34 (
35 {
36 prioqueue_seq => { '>', 0 } },
37 {
38 select => [ { max => 'prioqueue_seq' } ],
39 as => [ 'max_seq' ],
40 rows => 1,
41 }
42 )->first;
43 1 ▶ return $job_with_max_seq->get_column('max_seq')
Branch: 1 branch
BranchTrueFalseTotal
if $job_with_max_seq and defined $job_with_max_seq->get_column("max_seq") 0 1 1
Condition33%1/3
$job_with_max_seq and defined $job_with_max_seq->get_column("max_seq")
!ll&&!rl&&r
010
MC/DC0%0/2
$job_with_max_seq and defined $job_with_max_seq->get_column("max_seq")
$job_with_max_seq defined $job_with_max_seq->get_column("max_seq")
Truth table33%1/3
A and B
A= $job_with_max_seqB= defined $job_with_max_seq->get_column("max_seq")
ABresult
0X0
100
111
44 if $job_with_max_seq and defined $job_with_max_seq->get_column('max_seq');
45 1 return 0;
46 }
47  
48 1 ▶sub add {
Subroutine add: called CC=1 SCAR=0.0
Pod undocumented
49 1 my ($self, $job, $is_subtestrun) = @_;
50 1 my $max_seq = $self->_max_seq;
51 1 $job->prioqueue_seq($max_seq + 1);
52 1 $job->update;
53 1 my %job_hash = $job->get_inflated_columns;
54 1 my $obj_builder = Tapper::MCP::Scheduler::ObjectBuilder->instance;
55 1 push @{$self->testrunschedulings}, $obj_builder->new_job(%job_hash);
56 }
57  
58 46 ▶sub get_first_fitting {
Subroutine get_first_fitting: called CC=6 SCAR=18.2
Pod undocumented
59 46 my ($self, $free_hosts, $available_resources) = @_;
60  
61 46 foreach my $job (@{$self->testrunschedulings}) {
62 1 my $host = $job->fits($free_hosts);
63 1 ▶ next unless $host;
Branch: 1 branch
BranchTrueFalseTotal
unless $host 0 1 1
64  
65 # Check for unfinished dependencies
66 1 ▶ next unless $job->dependencies_finished;
Branch: 1 branch
BranchTrueFalseTotal
unless $job->dependencies_finished 0 1 1
67  
68 # Reserves resources, must run if $resources_available is 1
69 1 my ($resources_available,$acquireable_resources) =
70 $job->claim_resources($available_resources);
71 1 ▶ next unless $resources_available;
Branch: 1 branch
BranchTrueFalseTotal
unless $resources_available 0 1 1
72  
73 1 my $db_job = model('TestrunDB')->resultset('TestrunScheduling')->find($job->{id});
74 1 $db_job->host_id ($host->id);
75 1 $db_job->update;
76 1 ▶ if ($db_job->testrun->scenario_element) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db_job->testrun->scenario_element) 1 0 1
77 1 $db_job->testrun->scenario_element->is_fitted(1);
78 1 $db_job->testrun->scenario_element->update();
79 }
80  
81 1 return $db_job;
82 }
83 45 return;
84 }
85  
86 16 1;
87  
88 __END__
« MCP/Scheduler/Queue.pm ↑ Summary MCP/Info.pm »