# Copyright (C) Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, see <http://www.gnu.org/licenses/>.
package OpenQA::WebAPI::Plugin::FedoraUpdateRestart;
use strict;
use warnings;
use parent 'Mojolicious::Plugin';
use Mojo::IOLoop;
use OpenQA::Events;
use OpenQA::Schema::Result::Jobs;
sub register {
my ($self, $app) = @_;
OpenQA::Events->singleton->on("openqa_job_done" => sub { shift; $self->on_job_done($app, @_) });
}
# when a job completes, if it's an update test, it failed, and it's
# not already a clone, restart it, unless it's one of the FreeIPA
# tests (which don't work properly on restart and take forever). We
# could use the `dup_type_auto` behaviour, but that allows 3 restarts,
# which is kinda a lot.
sub on_job_done {
my ($self, $app, $args) = @_;
my ($user_id, $connection_id, $event, $event_data) = @$args;
my $job = $app->db->resultset('Jobs')->find({id => $event_data->{id}});
my $clone_of = $app->db->resultset("Jobs")->find({clone_id => $job->id});
if (
$job->result eq OpenQA::Schema::Result::Jobs::FAILED && !$clone_of &&
$job->FLAVOR =~ /^updates-/ &&
$job->TEST !~ /^.*(domain|realmd)/
) {
$job->auto_duplicate;
}
}
1;