Skip to content

Commit

Permalink
Improve minion guards for needle tasks
Browse files Browse the repository at this point in the history
In OpenQA::Task::Needle::Save we are now using a `limit_needle_task` guard
plus one for `git_clone_${needledir}_task`.

So in OpenQA::Task::Git::Clone we don't need the global limit_needle_task
anymore.

Issue: https://progress.opensuse.org/issues/164898
  • Loading branch information
perlpunk authored and okurz committed Oct 1, 2024
1 parent b638ad7 commit a9deba3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
12 changes: 7 additions & 5 deletions lib/OpenQA/Task/Git/Clone.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use Mojo::Base 'Mojolicious::Plugin', -signatures;
use Mojo::Util 'trim';

use Mojo::File;
use OpenQA::Log qw(log_debug);
use Time::Seconds 'ONE_HOUR';

sub register ($self, $app, @) {
Expand All @@ -24,15 +25,16 @@ sub _git_clone_all ($job, $clones) {
my $job_id = $job->id;

my $retry_delay = {delay => 30 + int(rand(10))};
# Don't interfere with any needle task
return $job->retry({delay => 5})
unless my $needle_guard = $app->minion->guard('limit_needle_task', 2 * ONE_HOUR);
# Prevent multiple git_clone tasks for the same path to run in parallel
my @guards;
for my $path (sort keys %$clones) {
$path = Mojo::File->new($path)->realpath if -e $path; # resolve symlinks
my $guard = $app->minion->guard("git_clone_${path}_task", 2 * ONE_HOUR);
return $job->retry($retry_delay) unless $guard;
my $guard_name = "git_clone_${path}_task";
my $guard = $app->minion->guard($guard_name, 2 * ONE_HOUR);
unless ($guard) {
log_debug("Could not get guard for $guard_name, retrying in $retry_delay->{delay}s");
return $job->retry($retry_delay);
}
push @guards, $guard;
}

Expand Down
5 changes: 4 additions & 1 deletion lib/OpenQA/Task/Needle/Save.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use OpenQA::Git;
use OpenQA::Jobs::Constants;
use OpenQA::Utils;
use Mojo::JSON 'decode_json';
use Time::Seconds 'ONE_HOUR';

sub register {
my ($self, $app) = @_;
Expand Down Expand Up @@ -55,7 +56,7 @@ sub _save_needle {

# prevent multiple save_needle and delete_needles tasks to run in parallel
return $minion_job->finish({error => 'Another save or delete needle job is ongoing. Try again later.'})
unless my $guard = $app->minion->guard('limit_needle_task', 7200);
unless my $guard = $app->minion->guard('limit_needle_task', 2 * ONE_HOUR);

my $schema = $app->schema;
my $openqa_job = $schema->resultset('Jobs')->find($args->{job_id});
Expand Down Expand Up @@ -99,6 +100,8 @@ sub _save_needle {
if (!$needledir || !(-d $needledir)) {
return $minion_job->fail({error => $needledir ? "$needledir is not a directory" : 'no needle directory'});
}
return $minion_job->finish({error => 'Another git_clone task is ongoing. Try again later.'})
unless my $git_clone_guard = $app->minion->guard("git_clone_${needledir}_task", 2 * ONE_HOUR);

# ensure needle dir is up-to-date
my $git = OpenQA::Git->new({app => $app, dir => $needledir, user => $user});
Expand Down
4 changes: 2 additions & 2 deletions t/14-grutasks-git.t
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ subtest 'git clone' => sub {
};

subtest 'minion guard' => sub {
my $guard = $t->app->minion->guard('limit_needle_task', ONE_HOUR);
my $guard = $t->app->minion->guard("git_clone_${git_clones}/opensuse_task", ONE_HOUR);
my $start = time;
$res = run_gru_job(@gru_args);
is $res->{state}, 'inactive', 'job is inactive';
ok(($res->{delayed} - $start) > 5, 'job delayed as expected');
ok(($res->{delayed} - $start) > 30, 'job delayed as expected');
};
};

Expand Down

0 comments on commit a9deba3

Please sign in to comment.