From d14c4b6726923b34f34feef18bc0fb03f94fc563 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Wed, 11 Jan 2023 14:59:12 +0000 Subject: [PATCH] #958 make job queue updates work reliably and atomically --- Changes | 3 ++- lib/App/Netdisco/JobQueue/PostgreSQL.pm | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Changes b/Changes index 7b017ee5..a509df92 100644 --- a/Changes +++ b/Changes @@ -3,7 +3,8 @@ [BUG FIXES] * #953 port reconfig (vlan) fail due to missing DB column data - * #957 race condition in job queue management when deleting one job + * #957 make job queue updates work reliably and atomically + * #958 make job queue updates work reliably and atomically 2.060003 - 2022-12-14 diff --git a/lib/App/Netdisco/JobQueue/PostgreSQL.pm b/lib/App/Netdisco/JobQueue/PostgreSQL.pm index e9b655f6..2ec392bc 100644 --- a/lib/App/Netdisco/JobQueue/PostgreSQL.pm +++ b/lib/App/Netdisco/JobQueue/PostgreSQL.pm @@ -173,7 +173,7 @@ sub jq_getsome { })->as_query, }], ], - }, {for => 'update'}) + }, { for => 'update' }) ->update({ status => 'info', log => (sprintf 'duplicate of %s', $job->id) }); debug sprintf 'getsome: cancelled %s duplicate(s) of job %s', ($gone || 0), $job->id; @@ -249,7 +249,7 @@ sub jq_defer { # lock db row and update to show job is available schema(vars->{'tenant'})->resultset('Admin') - ->find($job->id, {for => 'update'}) + ->search({ job => $job->id }, { for => 'update' }) ->update({ status => 'queued', started => undef }); }); $happy = true; @@ -280,7 +280,8 @@ sub jq_complete { } schema(vars->{'tenant'})->resultset('Admin') - ->find($job->id, {for => 'update'})->update({ + ->search({ job => $job->id }, { for => 'update' }) + ->update({ status => $job->status, log => $job->log, started => $job->started, @@ -385,8 +386,7 @@ sub jq_delete { if ($id) { schema(vars->{'tenant'})->txn_do(sub { - my $job = schema(vars->{'tenant'})->resultset('Admin')->find($id); - $job->delete() if $job; + schema(vars->{'tenant'})->resultset('Admin')->search({ job => $id })->delete; }); } else {