#958 make job queue updates work reliably and atomically

This commit is contained in:
Oliver Gorwits
2023-01-11 14:59:12 +00:00
parent 15a5e05a38
commit d14c4b6726
2 changed files with 7 additions and 6 deletions

View File

@@ -3,7 +3,8 @@
[BUG FIXES] [BUG FIXES]
* #953 port reconfig (vlan) fail due to missing DB column data * #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 2.060003 - 2022-12-14

View File

@@ -173,7 +173,7 @@ sub jq_getsome {
})->as_query, })->as_query,
}], }],
], ],
}, {for => 'update'}) }, { for => 'update' })
->update({ status => 'info', log => (sprintf 'duplicate of %s', $job->id) }); ->update({ status => 'info', log => (sprintf 'duplicate of %s', $job->id) });
debug sprintf 'getsome: cancelled %s duplicate(s) of job %s', ($gone || 0), $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 # lock db row and update to show job is available
schema(vars->{'tenant'})->resultset('Admin') schema(vars->{'tenant'})->resultset('Admin')
->find($job->id, {for => 'update'}) ->search({ job => $job->id }, { for => 'update' })
->update({ status => 'queued', started => undef }); ->update({ status => 'queued', started => undef });
}); });
$happy = true; $happy = true;
@@ -280,7 +280,8 @@ sub jq_complete {
} }
schema(vars->{'tenant'})->resultset('Admin') schema(vars->{'tenant'})->resultset('Admin')
->find($job->id, {for => 'update'})->update({ ->search({ job => $job->id }, { for => 'update' })
->update({
status => $job->status, status => $job->status,
log => $job->log, log => $job->log,
started => $job->started, started => $job->started,
@@ -385,8 +386,7 @@ sub jq_delete {
if ($id) { if ($id) {
schema(vars->{'tenant'})->txn_do(sub { schema(vars->{'tenant'})->txn_do(sub {
my $job = schema(vars->{'tenant'})->resultset('Admin')->find($id); schema(vars->{'tenant'})->resultset('Admin')->search({ job => $id })->delete;
$job->delete() if $job;
}); });
} }
else { else {