fix: serialize autonomy job leases
This commit is contained in:
@@ -31,7 +31,15 @@ function leaseNextJob(db, workerId, leaseSeconds = 60, jobTypes = null) {
|
||||
`).run(workerId, `+${Math.max(1, Math.floor(leaseSeconds))} seconds`, job.id);
|
||||
return updated.changes ? { ...job, status: 'leased', leased_by: workerId } : null;
|
||||
});
|
||||
return tx();
|
||||
try {
|
||||
// Acquire the write reservation before selecting. A deferred transaction can
|
||||
// otherwise read a snapshot, lose the writer race, and fail with
|
||||
// SQLITE_BUSY_SNAPSHOT when it attempts the lease update.
|
||||
return tx.immediate();
|
||||
} catch (error) {
|
||||
if (String(error.code || '').startsWith('SQLITE_BUSY')) return null;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function completeJob(db, id, workerId) {
|
||||
|
||||
Reference in New Issue
Block a user