diff --git a/lib/OpenQA/Task/Git/Clone.pm b/lib/OpenQA/Task/Git/Clone.pm index 29d995aea51..9a0f6c966ea 100644 --- a/lib/OpenQA/Task/Git/Clone.pm +++ b/lib/OpenQA/Task/Git/Clone.pm @@ -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; diff --git a/t/14-grutasks.t b/t/14-grutasks.t index 92c060d2820..78242a041e4 100644 --- a/t/14-grutasks.t +++ b/t/14-grutasks.t @@ -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 {