Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid archiving jobs to fail with "Job terminated unexpectedly" #4415

Merged
merged 1 commit into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/OpenQA/Schema/Result/Jobs.pm
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ sub archivable_result_dir ($self) {
return $result_dir && -d $result_dir ? $result_dir : undef;
}

sub archive ($self) {
sub archive ($self, $signal_guard = undef) {
return undef unless my $normal_result_dir = $self->archivable_result_dir;

my $archived_result_dir = $self->add_result_dir_prefix($self->remove_result_dir_prefix($normal_result_dir), 1);
Expand All @@ -270,6 +270,7 @@ sub archive ($self) {
die "Unable to copy '$normal_result_dir' to '$archived_result_dir': $error";
}

$signal_guard->retry(0) if $signal_guard;
Martchus marked this conversation as resolved.
Show resolved Hide resolved
$self->update({archived => 1});
$self->discard_changes;
File::Path::remove_tree($normal_result_dir);
Expand Down
3 changes: 2 additions & 1 deletion lib/OpenQA/Task/Job/ArchiveResults.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ sub register ($self, $app, @args) {
}

sub _archive_results ($minion_job, @args) {
my $ensure_task_retry_on_termination_signal_guard = OpenQA::Task::SignalGuard->new($minion_job);
Copy link
Member

@kraih kraih Dec 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's quite a name. 🥇

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name was suggested by @okurz in a previous PR review. I'm just using it consistently here as well.

my ($openqa_job_id) = @args;
my $app = $minion_job->app;
return $minion_job->fail('No job ID specified.') unless defined $openqa_job_id;
Expand All @@ -27,7 +28,7 @@ sub _archive_results ($minion_job, @args) {

my $openqa_job = $app->schema->resultset('Jobs')->find($openqa_job_id);
return $minion_job->finish("Job $openqa_job_id does not exist.") unless $openqa_job;
$minion_job->note(archived_path => $openqa_job->archive);
$minion_job->note(archived_path => $openqa_job->archive($ensure_task_retry_on_termination_signal_guard));
}

1;
5 changes: 4 additions & 1 deletion t/10-jobs.t
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,12 @@ subtest 'create result dir, delete results' => sub {
ok -d $result_dir, 'normal result directory still exists';
undef $copy_mock;

my $archive_dir = $job->archive;
my $signal_guard = OpenQA::Task::SignalGuard->new(undef);
my $archive_dir = $job->archive($signal_guard);
ok -d $archive_dir, 'archive result directory created';
ok !-d $result_dir, 'normal result directory removed';
ok !$signal_guard->retry, 'signal guard retry disabled in the end';
undef $signal_guard;

$result_dir = path($job->result_dir);
like $result_dir, qr|$base_dir/openqa/archive/testresults/\d{5}/\d{8}-to-be-archived|,
Expand Down
11 changes: 9 additions & 2 deletions t/14-grutasks.t
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,15 @@ subtest 'labeled jobs considered important' => sub {

# assume archiving is enabled
$app->config->{archiving}->{archive_preserved_important_jobs} = 1;
run_gru_job($app, 'limit_results_and_logs');
perform_minion_jobs($t->app->minion);
subtest 'run limit/archiving jobs' => sub {
my ($mock, @retry) = Test::MockModule->new('OpenQA::Task::SignalGuard');
$mock->redefine(retry => sub ($job, @args) { push @retry, [@args]; $mock->original('retry')->($job, @args) });
run_gru_job($app, 'limit_results_and_logs');
is_deeply \@retry, [[0]], 'retry disabled by limit task' or diag explain \@retry;
@retry = ();
perform_minion_jobs($t->app->minion);
is_deeply \@retry, [[0]], 'retry disabled by archiving task' or diag explain \@retry;
};
my $minion_jobs = $minion->jobs({tasks => ['archive_job_results']});
if (is $minion_jobs->total, 1, 'archiving job enqueued') {
my $archiving_job = $minion_jobs->next;
Expand Down