Browse Source

fix(core): Improve fault tolerance of "apply-collection-filters" job

Michael Bromley 4 years ago
parent
commit
be59bf9d57
1 changed files with 14 additions and 8 deletions
  1. 14 8
      packages/core/src/service/services/collection.service.ts

+ 14 - 8
packages/core/src/service/services/collection.service.ts

@@ -87,16 +87,22 @@ export class CollectionService implements OnModuleInit {
                 Logger.verbose(`Processing ${job.data.collectionIds.length} Collections`);
                 let completed = 0;
                 for (const collectionId of job.data.collectionIds) {
-                    const collection = await this.connection.getRepository(Collection).findOne(collectionId);
-                    if (!collection) {
+                    let collection: Collection | undefined;
+                    try {
+                        collection = await this.connection.getEntityOrThrow(ctx, Collection, collectionId, {
+                            retries: 3,
+                        });
+                    } catch (err) {
                         Logger.warn(`Could not find Collection with id ${collectionId}, skipping`);
-                        continue;
                     }
-                    const affectedVariantIds = await this.applyCollectionFiltersInternal(collection);
-                    job.setProgress(Math.ceil((++completed / job.data.collectionIds.length) * 100));
-                    this.eventBus.publish(
-                        new CollectionModificationEvent(ctx, collection, affectedVariantIds),
-                    );
+                    completed++;
+                    if (collection) {
+                        const affectedVariantIds = await this.applyCollectionFiltersInternal(collection);
+                        job.setProgress(Math.ceil((completed / job.data.collectionIds.length) * 100));
+                        this.eventBus.publish(
+                            new CollectionModificationEvent(ctx, collection, affectedVariantIds),
+                        );
+                    }
                 }
             },
         });