Skip to content

Commit 44e622e

Browse files
committed
Emit restart events when a job is enqueued
With this commit once the job goes to its end, it will check if it can restarted and if it fulfills the criteria, it will send the new job to the minion queue via `enqueue_restart`, where now it should populate the event. issue: https://progress.opensuse.org/issues/190557 Signed-off-by: Ioannis Bonatakis <[email protected]>
1 parent ad78558 commit 44e622e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/OpenQA/Schema/Result/Jobs.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,6 +2050,7 @@ sub enqueue_restart ($self, $options = {}) {
20502050
my $openqa_job_id = $self->id;
20512051
my $minion_job_id = OpenQA::App->singleton->gru->enqueue(restart_job => [$openqa_job_id], $options)->{minion_id};
20522052
log_debug "Enqueued restarting openQA job $openqa_job_id via Minion job $minion_job_id";
2053+
OpenQA::App->singleton->emit_event(openqa_job_restart => {id => $openqa_job_id});
20532054
return $minion_job_id;
20542055
}
20552056

t/23-amqp.t

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,16 @@ subtest 'extra TLS query params' => sub {
334334
is($last_publisher->url, $expected, 'url has all params');
335335
};
336336

337+
subtest 'enqueue_restart triggers amqp event and log' => sub {
338+
my $test_job = $schema->resultset('Jobs')->find(99945);
339+
my $minion_id;
340+
%published = (); # just to be sure
341+
combined_like { $minion_id = $test_job->enqueue_restart }
342+
qr/Enqueued restarting openQA job 99945 via Minion job \d+/, 'Debug log for enqueue_restart is present';
343+
ok $minion_id, 'Got a Minion job ID back';
344+
# each event contains keys(headers args body)
345+
is scalar(%published), 3, 'Exactly one event was published';
346+
is $published{args}{routing_key}, 'openqa.job.restart', 'enqueue_restart published amqp events';
347+
};
348+
337349
done_testing();

0 commit comments

Comments
 (0)