Cmd/Queue.pm

filter: Statementstmt 94.3% 50 / 53 Branchbran 58.3% 7 / 12 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 83.3% 70 / 84 CC 12 SCAR 16.9
CC
12
Cov
85%
update
8.6
del
5.1
add
2.0
CRAP 5.4
« Cmd/DbDeploy.pm ↑ Summary Cmd.pm »
1 package Tapper::Cmd::Queue;
2 3 our $AUTHORITY = 'cpan:TAPPER';
3 3 $Tapper::Cmd::Queue::VERSION = '5.0.14';
4 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use Tapper::Model 'model';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 extends 'Tapper::Cmd';
11  
12  
13  
14  
15  
16 3 ▶sub add {
Subroutine add: called CC=2 SCAR=6.9
Pod documented
17 3 my ($self, $args) = @_;
18 3 my %args = %{$args}; # copy
19  
20 3 $args{is_deleted} = 0;
21  
22 3 my $q = model('TestrunDB')->resultset('Queue')->update_or_create(\%args);
23 3 $q->insert;
24 3 my $all_queues = model('TestrunDB')->resultset('Queue');
25  
26  
27 # the new queue now has a much lower runcount than all others
28 # If we keep this situation the new queue would be scheduled
29 # until it catches up with the other queues. To prevent this we
30 # reset the runcount of all queues.
31 3 foreach my $queue ($all_queues->all) {
32 15 $queue->runcount($queue->priority);
33 15 $queue->update;
34 }
35 3 return $q->id;
36 }
37  
38  
39  
40 1 ▶sub update {
Subroutine update: called CC=7 SCAR=21.5
Pod documented
41 1 my ($self, $queue, $args) = @_;
42  
43 1 ▶ if (! (ref $queue && $queue->isa('Tapper::Schema::TestrunDB::Result::Queue')) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $queue and $queue->isa("Tapper::Schema::TestrunDB::Result::Queue")) 1 0 1
Condition33%1/3
ref $queue and $queue->isa("Tapper::Schema::TestrunDB::Result::Queue")
!ll&&!rl&&r
100
MC/DC0%0/2
ref $queue and $queue->isa("Tapper::Schema::TestrunDB::Result::Queue")
ref $queue $queue->isa("Tapper::Schema::TestrunDB::Result::Queue")
Truth table33%1/3
A and B
A= ref $queueB= $queue->isa("Tapper::Schema::TestrunDB::Result::Queue")
ABresult
0X0
100
111
44 1 $queue = model('TestrunDB')->resultset('Queue')->find( $queue );
45 }
46  
47 1 my $retval = $queue->update_content( $args );
48 1 my $all_queues = model('TestrunDB')->resultset('Queue');
49  
50 1 ▶ if (defined($args->{priority})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"priority"}) 1 0 1
51 # The priority of the queue has changed. Without the following
52 # changes the queue would be scheduled/not scheduled until its
53 # runcount is in correct relation to all others. Therefore, we
54 # reset the runcount to have scheduling working correctly immediatelly.
55 1 foreach my $queue ($all_queues->all) {
56 5 $queue->runcount($queue->priority);
57 5 $queue->update;
58 }
59 }
60  
61 1 require DateTime;
62 1 foreach my $queue ( model('TestrunDB')->resultset('Queue')->all ) {
63 5 ▶ if ( $queue->runcount ne $queue->priority ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($queue->runcount ne $queue->priority) 0 5 5
64 0 $queue->runcount( $queue->priority );
65 0 $queue->updated_at( DateTime->now->strftime('%F %T') );
66 0 $queue->update;
67 }
68 }
69  
70 1 return $retval;
71 }
72  
73  
74 2 ▶sub del {
Subroutine del: called CC=5 SCAR=16.2
Pod documented
75  
76 2 my ( $self, $queue, $force ) = @_;
77  
78 # queue is not a result object
79 2 ▶ if (! ref $queue ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $queue) 2 0 2
80 2 $queue = model('TestrunDB')->resultset('Queue')->find( $queue );
81 }
82  
83 # empty queues can be deleted, because it does not break anything
84 2 ▶ if ( $force || $queue->testrunschedulings->count == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($force or $queue->testrunschedulings->count == 0) { } 1 1 2
Condition66%2/3
$force or $queue->testrunschedulings->count == 0
l!l&&r!l&&!r
011
MC/DC50%1/2
$force or $queue->testrunschedulings->count == 0
$force $queue->testrunschedulings->count == 0
Truth table66%2/3
A or B
A= $forceB= $queue->testrunschedulings->count == 0
ABresult
1X1
011
000
85 1 $queue->delete;
86 }
87 else {
88  
89 1 require DateTime;
90 1 $queue->is_deleted( 1 );
91 1 $queue->active( 0 );
92 1 $queue->updated_at( DateTime->now->strftime('%F %T') );
93 1 $queue->update;
94  
95 1 ▶ if ( my $or_attached_jobs = $queue->testrunschedulings->search({ status => 'schedule' }) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $or_attached_jobs = $queue->testrunschedulings->search({"status", "schedule"})) 1 0 1
96 1 $or_attached_jobs->update({ status => 'finished' });
97 }
98 }
99  
100 2 return 0;
101  
102 }
103  
104 3 1; # End of Tapper::Cmd::Testrun
105  
106 __END__
« Cmd/DbDeploy.pm ↑ Summary Cmd.pm »