line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tapper::Cmd::Queue; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TAPPER'; |
3
|
|
|
|
|
|
|
$Tapper::Cmd::Queue::VERSION = '5.0.11'; |
4
|
2
|
|
|
2
|
|
5515009
|
use Moose; |
|
2
|
|
|
|
|
518994
|
|
|
2
|
|
|
|
|
15
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
14009
|
use DateTime; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
63
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
687
|
use Tapper::Model 'model'; |
|
2
|
|
|
|
|
4218
|
|
|
2
|
|
|
|
|
1177
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
extends 'Tapper::Cmd'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub add { |
17
|
3
|
|
|
3
|
1
|
29498
|
my ($self, $args) = @_; |
18
|
3
|
|
|
|
|
9
|
my %args = %{$args}; # copy |
|
3
|
|
|
|
|
14
|
|
19
|
|
|
|
|
|
|
|
20
|
3
|
|
|
|
|
12
|
$args{is_deleted} = 0; |
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
|
|
14
|
my $q = model('TestrunDB')->resultset('Queue')->update_or_create(\%args); |
23
|
3
|
|
|
|
|
63488
|
$q->insert; |
24
|
3
|
|
|
|
|
144
|
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
|
|
|
|
|
1790
|
foreach my $queue ($all_queues->all) { |
32
|
15
|
|
|
|
|
61053
|
$queue->runcount($queue->priority); |
33
|
15
|
|
|
|
|
2529
|
$queue->update; |
34
|
|
|
|
|
|
|
} |
35
|
3
|
|
|
|
|
26346
|
return $q->id; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub update { |
41
|
1
|
|
|
1
|
1
|
94487
|
my ($self, $queue, $args) = @_; |
42
|
|
|
|
|
|
|
|
43
|
1
|
50
|
33
|
|
|
9
|
if (! (ref $queue && $queue->isa('Tapper::Schema::TestrunDB::Result::Queue')) ) { |
44
|
1
|
|
|
|
|
5
|
$queue = model('TestrunDB')->resultset('Queue')->find( $queue ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
3853
|
my $retval = $queue->update_content( $args ); |
48
|
1
|
|
|
|
|
15364
|
my $all_queues = model('TestrunDB')->resultset('Queue'); |
49
|
|
|
|
|
|
|
|
50
|
1
|
50
|
|
|
|
353
|
if (defined($args->{priority})) { |
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
|
|
|
|
|
5
|
foreach my $queue ($all_queues->all) { |
56
|
5
|
|
|
|
|
48945
|
$queue->runcount($queue->priority); |
57
|
5
|
|
|
|
|
831
|
$queue->update; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
10881
|
require DateTime; |
62
|
1
|
|
|
|
|
99
|
foreach my $queue ( model('TestrunDB')->resultset('Queue')->all ) { |
63
|
5
|
50
|
|
|
|
2710
|
if ( $queue->runcount ne $queue->priority ) { |
64
|
0
|
|
|
|
|
0
|
$queue->runcount( $queue->priority ); |
65
|
0
|
|
|
|
|
0
|
$queue->updated_at( DateTime->now->strftime('%F %T') ); |
66
|
0
|
|
|
|
|
0
|
$queue->update; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
38
|
return $retval; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub del { |
75
|
|
|
|
|
|
|
|
76
|
2
|
|
|
2
|
1
|
29304
|
my ( $self, $queue, $force ) = @_; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# queue is not a result object |
79
|
2
|
50
|
|
|
|
13
|
if (! ref $queue ) { |
80
|
2
|
|
|
|
|
11
|
$queue = model('TestrunDB')->resultset('Queue')->find( $queue ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# empty queues can be deleted, because it does not break anything |
84
|
2
|
100
|
66
|
|
|
8521
|
if ( $force || $queue->testrunschedulings->count == 0 ) { |
85
|
1
|
|
|
|
|
7384
|
$queue->delete; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
else { |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
7805
|
require DateTime; |
90
|
1
|
|
|
|
|
30
|
$queue->is_deleted( 1 ); |
91
|
1
|
|
|
|
|
243
|
$queue->active( 0 ); |
92
|
1
|
|
|
|
|
56
|
$queue->updated_at( DateTime->now->strftime('%F %T') ); |
93
|
1
|
|
|
|
|
757
|
$queue->update; |
94
|
|
|
|
|
|
|
|
95
|
1
|
50
|
|
|
|
14328
|
if ( my $or_attached_jobs = $queue->testrunschedulings->search({ status => 'schedule' }) ) { |
96
|
1
|
|
|
|
|
1963
|
$or_attached_jobs->update({ status => 'finished' }); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
2
|
|
|
|
|
26303
|
return 0; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; # End of Tapper::Cmd::Testrun |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=pod |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=encoding UTF-8 |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 NAME |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Tapper::Cmd::Queue |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 SYNOPSIS |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This project offers backend functions for all projects that manipulate |
119
|
|
|
|
|
|
|
queues in the database. This module handles the testrun part. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
use Tapper::Cmd::Queue; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $bar = Tapper::Cmd::Queue->new(); |
124
|
|
|
|
|
|
|
$bar->add($testrun); |
125
|
|
|
|
|
|
|
... |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 NAME |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Tapper::Cmd::Queue - Backend functions for manipluation of queues in the database |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 FUNCTIONS |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 add |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Add a new queue to database. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 add |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Add a new queue. |
140
|
|
|
|
|
|
|
-- required -- |
141
|
|
|
|
|
|
|
* name - string |
142
|
|
|
|
|
|
|
* priority - int |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
@param hash ref - options for new queue |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
@return success - queue id |
147
|
|
|
|
|
|
|
@return error - undef |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 update |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Changes values of an existing queue. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
@param int or object ref - queue id or queue object |
154
|
|
|
|
|
|
|
@param hash ref - overwrite these options |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
@return success - queue id |
157
|
|
|
|
|
|
|
@return error - undef |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 del |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Delete a queue with given id. Its named del instead of delete to prevent |
162
|
|
|
|
|
|
|
confusion with the buildin delete function. If the queue is not empty |
163
|
|
|
|
|
|
|
and force is not given, we keep the queue and only set it to deleted to |
164
|
|
|
|
|
|
|
not break showing old testruns and their results. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
@param - queue result || queue id |
167
|
|
|
|
|
|
|
@param bool - force deleted |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
@return success - 0 |
170
|
|
|
|
|
|
|
@return error - error string |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 AUTHORS |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=over 4 |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item * |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
AMD OSRC Tapper Team <tapper@amd64.org> |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Tapper Team <tapper-ops@amazon.com> |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=back |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
This software is Copyright (c) 2020 by Advanced Micro Devices, Inc.. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
This is free software, licensed under: |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
The (two-clause) FreeBSD License |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |