« Tapper/Schema/TestrunDB/ResultSet/Precondition.pm
↑ Summary
Tapper/Schema/TestrunDB/Result/ReportgroupTestrunStats.pm »
| 1 | package Tapper::Schema::TestrunDB::Result::Queue; | ||||||||||
| 2 | 10 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||
| 3 | 10 | $Tapper::Schema::TestrunDB::Result::Queue::VERSION = '5.0.12'; | |||||||||
| 4 | # ABSTRACT: Tapper - Containing queues of testruns | ||||||||||
| 5 | |||||||||||
| 6 | 10 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 10 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 10 | ▶ | use parent 'DBIx::Class'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 10 | __PACKAGE__->load_components(qw/InflateColumn::DateTime Core/); | |||||||||
| 12 | 10 | __PACKAGE__->table("queue"); | |||||||||
| 13 | 10 | __PACKAGE__->add_columns | |||||||||
| 14 | ( | ||||||||||
| 15 | "id", { data_type => "INT", default_value => undef, is_nullable => 0, size => 11, is_auto_increment => 1, }, | ||||||||||
| 16 | "name", { data_type => "VARCHAR", default_value => "", is_nullable => 1, size => 255, }, | ||||||||||
| 17 | "priority", { data_type => "INT", default_value => 0, is_nullable => 0, size => 10, }, | ||||||||||
| 18 | "runcount", { data_type => "INT", default_value => 0, is_nullable => 0, size => 10, }, # aux for algorithm | ||||||||||
| 19 | "active", { data_type => "INT", default_value => 0, is_nullable => 1, size => 1, }, | ||||||||||
| 20 | "is_deleted", { data_type => "TINYINT", default_value => "0", is_nullable => 1, }, # deleted queues need to be kept in db to show old testruns correctly | ||||||||||
| 21 | "created_at", { data_type => "TIMESTAMP", default_value => \'CURRENT_TIMESTAMP', is_nullable => 1, }, #' emacs highlight bug | ||||||||||
| 22 | "updated_at", { data_type => "DATETIME", default_value => undef, is_nullable => 1, }, | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | 10 | (my $basepkg = __PACKAGE__) =~ s/::\w+$//; | |||||||||
| 26 | |||||||||||
| 27 | 10 | __PACKAGE__->set_primary_key("id"); | |||||||||
| 28 | 10 | __PACKAGE__->add_unique_constraint( unique_queue_name => [ qw/name/ ], ); | |||||||||
| 29 | 10 | __PACKAGE__->has_many ( testrunschedulings => 'Tapper::Schema::TestrunDB::Result::TestrunScheduling', { 'foreign.queue_id' => 'self.id' }); | |||||||||
| 30 | 10 | __PACKAGE__->has_many ( queuehosts => "${basepkg}::QueueHost", { 'foreign.queue_id' => 'self.id' }); | |||||||||
| 31 | 10 | __PACKAGE__->has_many ( deniedhosts => "${basepkg}::DeniedHost", { 'foreign.queue_id' => 'self.id' }); | |||||||||
| 32 | |||||||||||
| 33 | # -------------------- methods on results -------------------- | ||||||||||
| 34 | |||||||||||
| 35 | |||||||||||
| 36 | sub queued_testruns | ||||||||||
| 37 | 0 | ▶ | { | ||||||||
|
Subroutine
queued_testruns: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 38 | 0 | my ($self) = @_; | |||||||||
| 39 | |||||||||||
| 40 | 0 | $self->testrunschedulings->search({ | |||||||||
| 41 | status => 'schedule' | ||||||||||
| 42 | }, | ||||||||||
| 43 | { | ||||||||||
| 44 | order_by => 'testrun_id' | ||||||||||
| 45 | }); | ||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | |||||||||||
| 49 | sub get_first_fitting | ||||||||||
| 50 | 0 | ▶ | { | ||||||||
|
Subroutine
get_first_fitting: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 51 | 0 | my ($self, $free_hosts) = @_; | |||||||||
| 52 | 0 | my $jobs = $self->queued_testruns; | |||||||||
| 53 | 0 | foreach my $job ($jobs->all()) { | |||||||||
| 54 | 0 | ▶ | if (my $host = $job->fits($free_hosts)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 0 | $job->host_id ($host->id); | |||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | if ($job->testrun->scenario_element) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 0 | $job->testrun->scenario_element->is_fitted(1); | |||||||||
| 59 | 0 | $job->testrun->scenario_element->update(); | |||||||||
| 60 | } | ||||||||||
| 61 | 0 | return $job; | |||||||||
| 62 | } | ||||||||||
| 63 | } | ||||||||||
| 64 | 0 | return; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | |||||||||||
| 68 | sub to_string | ||||||||||
| 69 | 0 | ▶ | { | ||||||||
|
Subroutine
to_string: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 70 | 0 | my ($self) = @_; | |||||||||
| 71 | |||||||||||
| 72 | 0 | my $format = join( $Tapper::Schema::TestrunDB::DELIM, qw/%s %s %s %s %s %s %s %s %s %s %s %s %s %s /, ''); | |||||||||
| 73 | sprintf ( | ||||||||||
| 74 | $format, | ||||||||||
| 75 | map { | ||||||||||
| 76 | 0 | ▶ | defined $self->$_ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | ? $self->$_ | ||||||||||
| 78 | : $Tapper::Schema::TestrunDB::NULL | ||||||||||
| 79 | 0 | } @{$self->result_source->{_ordered_columns} } | |||||||||
| 80 | ); | ||||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | |||||||||||
| 84 | sub is_member | ||||||||||
| 85 | 0 | ▶ | { | ||||||||
|
Subroutine
is_member: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 86 | 0 | my ($head, @tail) = @_; | |||||||||
| 87 | 0 | grep { $head->id eq $_->id } @tail; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | |||||||||||
| 91 | sub ordered_preconditions | ||||||||||
| 92 | 0 | ▶ | { | ||||||||
|
Subroutine
ordered_preconditions: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 93 | 0 | my ($self) = @_; | |||||||||
| 94 | |||||||||||
| 95 | 0 | my @done = (); | |||||||||
| 96 | 0 | my %seen = (); | |||||||||
| 97 | 0 | my @todo = (); | |||||||||
| 98 | |||||||||||
| 99 | 0 | @todo = $self->preconditions->search({}, {order_by => 'succession'})->all; | |||||||||
| 100 | |||||||||||
| 101 | 0 | ▶ | while (my $head = shift @todo) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 102 | { | ||||||||||
| 103 | 0 | ▶ | if ($seen{$head->id}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 104 | { | ||||||||||
| 105 | 0 | ▶ | push @done, $head unless is_member($head, @done); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | } | ||||||||||
| 107 | else | ||||||||||
| 108 | { | ||||||||||
| 109 | 0 | $seen{$head->id} = 1; | |||||||||
| 110 | 0 | my @pre_todo = $head->child_preconditions->search({}, { order_by => 'succession' } )->all; | |||||||||
| 111 | 0 | unshift @todo, @pre_todo, $head; | |||||||||
| 112 | } | ||||||||||
| 113 | } | ||||||||||
| 114 | 0 | return @done; | |||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | |||||||||||
| 118 | sub producer | ||||||||||
| 119 | 0 | ▶ | { | ||||||||
|
Subroutine
producer: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 120 | 0 | my ($self) = @_; | |||||||||
| 121 | |||||||||||
| 122 | 0 | my $producer_class = "Tapper::MCP::Scheduler::PreconditionProducer::".$self->producer; | |||||||||
| 123 | 0 | eval "use $producer_class"; ## no critic (ProhibitStringyEval) | |||||||||
| 124 | 0 | ▶ | return $producer_class->new unless $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 125 | 0 | return; | |||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | |||||||||||
| 129 | sub produce | ||||||||||
| 130 | 0 | ▶ | { | ||||||||
|
Subroutine
produce: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 131 | 0 | my ($self, $request) = @_; | |||||||||
| 132 | |||||||||||
| 133 | 0 | my $producer = $self->producer; | |||||||||
| 134 | |||||||||||
| 135 | 0 | ▶ | if (not $producer) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 136 | 0 | warn "Queue ".$self->name." does not have an associated producer"; | |||||||||
| 137 | } else { | ||||||||||
| 138 | 0 | print STDERR "Queue.producer: ", Dumper($producer); | |||||||||
| 139 | 0 | return $producer->produce($request); | |||||||||
| 140 | } | ||||||||||
| 141 | } | ||||||||||
| 142 | |||||||||||
| 143 | |||||||||||
| 144 | 0 | ▶ | sub update_content { | ||||||||
|
Subroutine
update_content: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 145 | 0 | my ($self, $args) =@_; | |||||||||
| 146 | |||||||||||
| 147 | 0 | require DateTime; | |||||||||
| 148 | 0 | ▶ | $self->priority( $args->{priority} ) if exists($args->{priority}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 149 | 0 | ▶ | $self->active( $args->{active} ) if exists($args->{active}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 150 | 0 | $self->updated_at( DateTime->now->strftime('%F %T') ); | |||||||||
| 151 | 0 | $self->update; | |||||||||
| 152 | |||||||||||
| 153 | 0 | return $self->id; | |||||||||
| 154 | } | ||||||||||
| 155 | |||||||||||
| 156 | 10 | 1; | |||||||||
| 157 | |||||||||||
| 158 | __END__ | ||||||||||