Skip to content

Commit 1a089dd

Browse files
committed
fix: prevent double-claim on SQLite with status guard
1 parent 9bc5fa8 commit 1a089dd

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/drivers/knex_adapter.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,24 @@ export class KnexAdapter implements Adapter {
177177
}
178178

179179
// Update job to active status
180-
await trx(this.#jobsTable).where('id', job.id).where('queue', queue).update({
180+
// For SQLite (no SKIP LOCKED), add status='pending' guard to prevent double-claim
181+
const updateQuery = trx(this.#jobsTable).where('id', job.id).where('queue', queue)
182+
183+
if (!this.#supportsSkipLocked()) {
184+
updateQuery.where('status', 'pending')
185+
}
186+
187+
const updated = await updateQuery.update({
181188
status: 'active',
182189
worker_id: this.#workerId,
183190
acquired_at: now,
184191
})
185192

193+
// Another worker already claimed this job
194+
if (updated === 0) {
195+
return null
196+
}
197+
186198
const jobData: JobData = JSON.parse(job.data)
187199

188200
return {

0 commit comments

Comments
 (0)