Browse Source

fix(core): Reinstate correct locking in SqlJobQueueStrategy

Michael Bromley 4 years ago
parent
commit
357189f1a9

+ 2 - 1
packages/core/src/plugin/default-job-queue-plugin/sql-job-queue-strategy.ts

@@ -61,7 +61,7 @@ export class SqlJobQueueStrategy extends PollingJobQueueStrategy implements Insp
                 // set a lock on that row and immediately update the status to "RUNNING".
                 // This prevents multiple worker processes from taking the same job when
                 // running concurrent workers.
-                await connection.transaction(async transactionManager => {
+                connection.transaction(async transactionManager => {
                     const result = await this.getNextAndSetAsRunning(transactionManager, queueName);
                     resolve(result);
                 });
@@ -85,6 +85,7 @@ export class SqlJobQueueStrategy extends PollingJobQueueStrategy implements Insp
                 }),
             )
             .orderBy('record.createdAt', 'ASC')
+            .setLock('pessimistic_write')
             .getOne();
         if (record) {
             const job = this.fromRecord(record);