Skip to content

Commit

Permalink
Merge pull request #5862 from perlpunk/minion-guard
Browse files Browse the repository at this point in the history
Prevent git_clone to interfere with needle tasks
  • Loading branch information
mergify[bot] authored Aug 17, 2024
2 parents 458533e + 6f0fc37 commit c2bbc49
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/OpenQA/Task/Git/Clone.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ sub _git_clone_all ($job, $clones) {
my $app = $job->app;
my $job_id = $job->id;

# Prevent multiple git clone tasks for the same path to run in parallel
my @guards;
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
$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;
push(@guards, $guard);
push @guards, $guard;
}

my $log = $app->log;
Expand Down
8 changes: 8 additions & 0 deletions t/14-grutasks.t
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,14 @@ subtest 'git clone' => sub {
is $res->{retries}, 0, 'job retries not incremented';
is $res->{state}, 'failed', 'job considered failed';
};

subtest 'minion guard' => sub {
my $guard = $t->app->minion->guard('limit_needle_task', ONE_HOUR);
my $start = time;
$res = run_gru_job($t->app, 'git_clone', $clone_dirs, {priority => 10});
is $res->{state}, 'inactive', 'job is inactive';
ok(($res->{delayed} - $start) > 5, 'job delayed as expected');
};
};

subtest 'download assets with correct permissions' => sub {
Expand Down

0 comments on commit c2bbc49

Please sign in to comment.