« Tapper/Schema/TestrunDB/Result/Testrun.pm
↑ Summary
Tapper/Schema/TestrunDB/ResultSet/Precondition.pm »
| 1 | # TODO: rename into "(Scheduler|Result)::Job"? | ||||||||||
| 2 | |||||||||||
| 3 | package Tapper::Schema::TestrunDB::Result::TestrunScheduling; | ||||||||||
| 4 | 10 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||
| 5 | 10 | $Tapper::Schema::TestrunDB::Result::TestrunScheduling::VERSION = '5.0.12'; | |||||||||
| 6 | # ABSTRACT: Tapper - Containing informations for an executed testrun | ||||||||||
| 7 | |||||||||||
| 8 | 10 | ▶ | use YAML::Syck; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | ## no critic (RequireUseStrict) | ||||||||||
| 10 | 10 | ▶ | use parent 'DBIx::Class'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 10 | __PACKAGE__->load_components("InflateColumn::Object::Enum", "Core"); | |||||||||
| 13 | 10 | __PACKAGE__->table("testrun_scheduling"); | |||||||||
| 14 | 10 | __PACKAGE__->add_columns | |||||||||
| 15 | ( | ||||||||||
| 16 | "id", { data_type => "INT", default_value => undef, is_nullable => 0, size => 11, is_auto_increment => 1, }, | ||||||||||
| 17 | "testrun_id", { data_type => "INT", default_value => undef, is_nullable => 0, size => 11, is_foreign_key => 1, }, | ||||||||||
| 18 | "queue_id", { data_type => "INT", default_value => 0, is_nullable => 1, size => 11, is_foreign_key => 1, }, | ||||||||||
| 19 | "host_id", { data_type => "INT", default_value => undef, is_nullable => 1, size => 11, is_foreign_key => 1, }, | ||||||||||
| 20 | "prioqueue_seq", { data_type => "INT", default_value => undef, is_nullable => 1, size => 11, }, | ||||||||||
| 21 | "status", { data_type => "VARCHAR", default_value => "prepare", is_nullable => 1, size => 255, is_enum => 1, extra => { list => [qw(prepare schedule running finished)] } }, | ||||||||||
| 22 | "auto_rerun", { data_type => "TINYINT", default_value => "0", is_nullable => 1, }, | ||||||||||
| 23 | "created_at", { data_type => "TIMESTAMP", default_value => \'CURRENT_TIMESTAMP', is_nullable => 1, }, # ' | ||||||||||
| 24 | "updated_at", { data_type => "DATETIME", default_value => undef, is_nullable => 1, }, | ||||||||||
| 25 | ); | ||||||||||
| 26 | |||||||||||
| 27 | 10 | __PACKAGE__->set_primary_key(qw/id/); | |||||||||
| 28 | |||||||||||
| 29 | 10 | (my $basepkg = __PACKAGE__) =~ s/::\w+$//; | |||||||||
| 30 | |||||||||||
| 31 | 10 | __PACKAGE__->belongs_to( testrun => "${basepkg}::Testrun", { 'foreign.id' => 'self.testrun_id' }); | |||||||||
| 32 | 10 | __PACKAGE__->belongs_to( queue => "${basepkg}::Queue", { 'foreign.id' => 'self.queue_id' }); | |||||||||
| 33 | 10 | __PACKAGE__->belongs_to( host => "${basepkg}::Host", { 'foreign.id' => 'self.host_id' }); | |||||||||
| 34 | |||||||||||
| 35 | 10 | __PACKAGE__->has_many ( requested_features => "${basepkg}::TestrunRequestedFeature", { 'foreign.testrun_id' => 'self.testrun_id' }); | |||||||||
| 36 | 10 | __PACKAGE__->has_many ( requested_hosts => "${basepkg}::TestrunRequestedHost", { 'foreign.testrun_id' => 'self.testrun_id' }); | |||||||||
| 37 | 10 | __PACKAGE__->has_many ( requested_resources => "${basepkg}::TestrunRequestedResource", { 'foreign.testrun_id' => 'self.testrun_id' }); | |||||||||
| 38 | 10 | __PACKAGE__->has_many ( | |||||||||
| 39 | claimed_resources => "${basepkg}::Resource", | ||||||||||
| 40 | { 'foreign.used_by_scheduling_id' => 'self.id' }, | ||||||||||
| 41 | { 'cascade_delete' => 0 }, | ||||||||||
| 42 | ); | ||||||||||
| 43 | |||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | |||||||||||
| 47 | 0 | ▶ | sub update_content { | ||||||||
|
Subroutine
update_content: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 48 | 0 | my ($self, $args) =@_; | |||||||||
| 49 | |||||||||||
| 50 | 0 | ▶ | $self->queue_id ( $args->{queue_id} ) if $args->{queue_id}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 0 | ▶ | $self->host_id ( $args->{host_id} ) if $args->{host_id}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 0 | ▶ | $self->status ( $args->{status} ) if $args->{status}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 0 | ▶ | $self->auto_rerun ( $args->{auto_rerun} ) if $args->{auto_rerun}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | $self->update; | |||||||||
| 55 | 0 | return $self->id; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | |||||||||||
| 59 | sub mark_as_running | ||||||||||
| 60 | 3 | ▶ | { | ||||||||
|
Subroutine
mark_as_running: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 61 | 3 | my ($self) = @_; | |||||||||
| 62 | |||||||||||
| 63 | # need a transaction because someone might access this | ||||||||||
| 64 | # variable on the CLI | ||||||||||
| 65 | 3 | my $guard = $self->result_source->schema->txn_scope_guard; | |||||||||
| 66 | |||||||||||
| 67 | 3 | ▶ | if ($self->host->is_pool) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 3 | $self->host->get_from_storage; | |||||||||
| 69 | 3 | $self->host->pool_free($self->host->pool_free-1); | |||||||||
| 70 | 3 | ▶ | $self->host->free(0) if $self->host->pool_free == 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | } else { | ||||||||||
| 72 | 0 | $self->host->free(0); | |||||||||
| 73 | } | ||||||||||
| 74 | 3 | $self->host->update; | |||||||||
| 75 | |||||||||||
| 76 | 3 | $self->prioqueue_seq(undef); | |||||||||
| 77 | 3 | $self->status("running"); | |||||||||
| 78 | 3 | $self->update; | |||||||||
| 79 | |||||||||||
| 80 | 3 | $guard->commit; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | |||||||||||
| 84 | sub mark_as_finished | ||||||||||
| 85 | 1 | ▶ | { | ||||||||
|
Subroutine
mark_as_finished: called CC=4 SCAR=14.9
Pod
documented
| |||||||||||
| 86 | 1 | my ($self) = @_; | |||||||||
| 87 | |||||||||||
| 88 | # need a transaction because someone might access this | ||||||||||
| 89 | # variable on the CLI | ||||||||||
| 90 | 1 | my $guard = $self->result_source->schema->txn_scope_guard; | |||||||||
| 91 | |||||||||||
| 92 | 1 | ▶ | if ($self->host->is_pool) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | 1 | $self->host($self->host->get_from_storage); | |||||||||
| 94 | 1 | $self->host->pool_free($self->host->pool_free+1); | |||||||||
| 95 | 1 | ▶ | if ($self->host->pool_free > 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | 1 | $self->host->free(1); | |||||||||
| 97 | } | ||||||||||
| 98 | } else { | ||||||||||
| 99 | 0 | ▶ | if ($self->host->testrunschedulings->search({status => "running"})->count == 1) { # mitigate scheduler bug where multiple jobs run on same host; this condition here hopefully recovers the situation. | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | 0 | $self->host->free(1); | |||||||||
| 101 | } | ||||||||||
| 102 | } | ||||||||||
| 103 | 1 | $self->host->update; | |||||||||
| 104 | 1 | $self->status("finished"); | |||||||||
| 105 | 1 | $self->update; | |||||||||
| 106 | |||||||||||
| 107 | # Free resources | ||||||||||
| 108 | 1 | $self->claimed_resources->update({ used_by_scheduling_id => undef }); | |||||||||
| 109 | |||||||||||
| 110 | 1 | $guard->commit; | |||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | |||||||||||
| 114 | sub sqlt_deploy_hook | ||||||||||
| 115 | 8 | ▶ | { | ||||||||
|
Subroutine
sqlt_deploy_hook: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 116 | 8 | my ($self, $sqlt_table) = @_; | |||||||||
| 117 | 8 | $sqlt_table->add_index(name => 'testrun_scheduling_idx_created_at', fields => ['created_at']); | |||||||||
| 118 | 8 | $sqlt_table->add_index(name => 'testrun_scheduling_idx_status', fields => ['status']); | |||||||||
| 119 | } | ||||||||||
| 120 | |||||||||||
| 121 | 10 | 1; | |||||||||
| 122 | |||||||||||
| 123 | __END__ | ||||||||||