From 8077e3de9dc40a67e496761b0f996ad3b46b65ec Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 17 May 2014 20:31:18 +0100 Subject: [PATCH] remove any duplicate jobs when locking --- Netdisco/lib/App/Netdisco/JobQueue/PostgreSQL.pm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Netdisco/lib/App/Netdisco/JobQueue/PostgreSQL.pm b/Netdisco/lib/App/Netdisco/JobQueue/PostgreSQL.pm index 9e32072c..42d0c3b6 100644 --- a/Netdisco/lib/App/Netdisco/JobQueue/PostgreSQL.pm +++ b/Netdisco/lib/App/Netdisco/JobQueue/PostgreSQL.pm @@ -59,9 +59,9 @@ sub jq_queued { my $job_type = shift; return schema('netdisco')->resultset('Admin')->search({ - device => { '!=' => undef}, - action => $job_type, - status => { -like => 'queued%' }, + device => { '!=' => undef}, + action => $job_type, + status => { -like => 'queued%' }, })->get_column('device')->all; } @@ -109,6 +109,15 @@ sub jq_lock { schema('netdisco')->resultset('Admin') ->find($job->id, {for => 'update'}) ->update({ status => "queued-$fqdn" }); + + # remove any duplicate jobs, needed because we have race conditions + # when queueing jobs of a type for all devices + schema('netdisco')->resultset('Admin')->search({ + device => $job->device, + port => $job->port, + action => $job->action, + subaction => $job->subaction, + }, {for => 'update'})->delete(); }); $happy = true; };