Browse Source

fix(core): Fix race condition in updating JobRecords

Michael Bromley 4 years ago
parent
commit
b446c8f3f5

+ 0 - 1
packages/core/e2e/default-search-plugin.e2e-spec.ts

@@ -4,7 +4,6 @@ import {
     DefaultJobQueuePlugin,
     DefaultJobQueuePlugin,
     DefaultSearchPlugin,
     DefaultSearchPlugin,
     facetValueCollectionFilter,
     facetValueCollectionFilter,
-    JobQueueService,
     mergeConfig,
     mergeConfig,
 } from '@vendure/core';
 } from '@vendure/core';
 import { createTestEnvironment, E2E_DEFAULT_CHANNEL_TOKEN, SimpleGraphQLClient } from '@vendure/testing';
 import { createTestEnvironment, E2E_DEFAULT_CHANNEL_TOKEN, SimpleGraphQLClient } from '@vendure/testing';

+ 1 - 1
packages/core/e2e/utils/await-running-jobs.ts

@@ -13,7 +13,7 @@ export async function awaitRunningJobs(adminClient: SimpleGraphQLClient, timeout
     let timedOut = false;
     let timedOut = false;
     // Allow a brief period for the jobs to start in the case that
     // Allow a brief period for the jobs to start in the case that
     // e.g. event debouncing is used before triggering the job.
     // e.g. event debouncing is used before triggering the job.
-    await new Promise((resolve) => setTimeout(resolve, 100));
+    await new Promise(resolve => setTimeout(resolve, 100));
     do {
     do {
         const { jobs } = await adminClient.query<GetRunningJobs.Query, GetRunningJobs.Variables>(
         const { jobs } = await adminClient.query<GetRunningJobs.Query, GetRunningJobs.Variables>(
             GET_RUNNING_JOBS,
             GET_RUNNING_JOBS,

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

@@ -112,7 +112,7 @@ export class SqlJobQueueStrategy extends PollingJobQueueStrategy implements Insp
             .update()
             .update()
             .set(this.toRecord(job))
             .set(this.toRecord(job))
             .where('id = :id', { id: job.id })
             .where('id = :id', { id: job.id })
-            .andWhere('state != :cancelled', { cancelled: JobState.CANCELLED })
+            .andWhere('settledAt IS NULL')
             .execute();
             .execute();
     }
     }
 
 

+ 0 - 1
packages/elasticsearch-plugin/e2e/elasticsearch-plugin.e2e-spec.ts

@@ -344,7 +344,6 @@ describe('Elasticsearch plugin', () => {
                         })),
                         })),
                     },
                     },
                 );
                 );
-
                 await awaitRunningJobs(adminClient);
                 await awaitRunningJobs(adminClient);
                 const { search: search2 } = await doAdminSearchQuery(adminClient, {
                 const { search: search2 } = await doAdminSearchQuery(adminClient, {
                     term: 'drive',
                     term: 'drive',