diff --git a/lib/OpenQA/Task/Git/Clone.pm b/lib/OpenQA/Task/Git/Clone.pm index 08642399b4b3..5677ff303da1 100644 --- a/lib/OpenQA/Task/Git/Clone.pm +++ b/lib/OpenQA/Task/Git/Clone.pm @@ -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, @) { @@ -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; } diff --git a/lib/OpenQA/Task/Needle/Save.pm b/lib/OpenQA/Task/Needle/Save.pm index 88a99168494b..d7105dd0a5cc 100644 --- a/lib/OpenQA/Task/Needle/Save.pm +++ b/lib/OpenQA/Task/Needle/Save.pm @@ -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) = @_; @@ -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}); @@ -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}); diff --git a/t/14-grutasks-git.t b/t/14-grutasks-git.t index d19840be0220..a4d40664b2a5 100644 --- a/t/14-grutasks-git.t +++ b/t/14-grutasks-git.t @@ -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'); }; };