Skip to content

Commit 375b788

Browse files
committed
Add row locking with FOR UPDATE in delete query
1 parent d6b44d1 commit 375b788

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

apps/webapp/app/platform/zodWorker.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ export class ZodWorker<TMessageCatalog extends MessageCatalogSchema> {
516516
});
517517

518518
const rawResults = await this.#prisma.$queryRawUnsafe(
519-
`WITH rows AS (SELECT id FROM ${this.graphileWorkerSchema}.jobs WHERE run_at < $1 AND locked_at IS NULL AND max_attempts = attempts ORDER BY run_at ASC LIMIT $2) DELETE FROM ${this.graphileWorkerSchema}.jobs WHERE id IN (SELECT id FROM rows) RETURNING id`,
519+
`WITH rows AS (SELECT id FROM ${this.graphileWorkerSchema}.jobs WHERE run_at < $1 AND locked_at IS NULL AND max_attempts = attempts LIMIT $2 FOR UPDATE) DELETE FROM ${this.graphileWorkerSchema}.jobs WHERE id IN (SELECT id FROM rows) RETURNING id`,
520520
expirationDate,
521521
this.#cleanup.maxCount
522522
);

0 commit comments

Comments
 (0)