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

Prevent git_clone to interfere with needle tasks #5862

Merged
merged 1 commit into from
Aug 17, 2024
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
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
Loading