From 62913185afd9df164ffeace9fba5a0792c73014c Mon Sep 17 00:00:00 2001 From: Stevche Radevski Date: Mon, 5 Aug 2024 12:31:47 +0200 Subject: [PATCH] fix: Upgrade bullmq and adjust to breaking changes in repeatable jobs --- packages/modules/event-bus-redis/package.json | 2 +- .../modules/workflow-engine-redis/package.json | 2 +- .../src/utils/workflow-orchestrator-storage.ts | 16 +++------------- yarn.lock | 12 ++++++------ 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/packages/modules/event-bus-redis/package.json b/packages/modules/event-bus-redis/package.json index 03778631b0cb9..3ad977312724c 100644 --- a/packages/modules/event-bus-redis/package.json +++ b/packages/modules/event-bus-redis/package.json @@ -37,7 +37,7 @@ "@medusajs/modules-sdk": "^1.12.11", "@medusajs/utils": "^1.11.9", "awilix": "^8.0.0", - "bullmq": "^5.4.2", + "bullmq": "5.12.0", "ioredis": "^5.2.5" } } diff --git a/packages/modules/workflow-engine-redis/package.json b/packages/modules/workflow-engine-redis/package.json index 4a3877442cf12..b5089a0268ce5 100644 --- a/packages/modules/workflow-engine-redis/package.json +++ b/packages/modules/workflow-engine-redis/package.json @@ -52,7 +52,7 @@ "@mikro-orm/migrations": "5.9.7", "@mikro-orm/postgresql": "5.9.7", "awilix": "^8.0.0", - "bullmq": "^5.4.2", + "bullmq": "5.12.0", "dotenv": "^16.4.5", "ioredis": "^5.3.2", "knex": "2.4.2" diff --git a/packages/modules/workflow-engine-redis/src/utils/workflow-orchestrator-storage.ts b/packages/modules/workflow-engine-redis/src/utils/workflow-orchestrator-storage.ts index b7107e201796c..9aff012499b06 100644 --- a/packages/modules/workflow-engine-redis/src/utils/workflow-orchestrator-storage.ts +++ b/packages/modules/workflow-engine-redis/src/utils/workflow-orchestrator-storage.ts @@ -374,10 +374,7 @@ export class RedisDistributedTransactionStorage const jobId = typeof jobDefinition === "string" ? jobDefinition : jobDefinition.jobId - // In order to ensure that the schedule configuration is always up to date, we first cancel an existing job, if there was one - // any only then we add the new one. - await this.remove(jobId) - + // If it is the same key (eg. the same workflow name), the old one will get overridden. await this.queue.add( JobType.SCHEDULE, { @@ -388,21 +385,14 @@ export class RedisDistributedTransactionStorage repeat: { pattern: schedulerOptions.cron, limit: schedulerOptions.numberOfExecutions, + key: `${JobType.SCHEDULE}_${jobId}`, }, - jobId: `${JobType.SCHEDULE}_${jobId}`, } ) } async remove(jobId: string): Promise { - const repeatableJobs = await this.queue.getRepeatableJobs() - const job = repeatableJobs.find( - (job) => job.id === `${JobType.SCHEDULE}_${jobId}` - ) - - if (job) { - await this.queue.removeRepeatableByKey(job.key) - } + await this.queue.removeRepeatableByKey(`${JobType.SCHEDULE}_${jobId}`) } async removeAll(): Promise { diff --git a/yarn.lock b/yarn.lock index 59d116cf5c092..98de55aa4754c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4543,7 +4543,7 @@ __metadata: "@medusajs/types": ^1.11.16 "@medusajs/utils": ^1.11.9 awilix: ^8.0.0 - bullmq: ^5.4.2 + bullmq: 5.12.0 cross-env: ^5.2.1 ioredis: ^5.2.5 jest: ^29.7.0 @@ -5473,7 +5473,7 @@ __metadata: "@mikro-orm/migrations": 5.9.7 "@mikro-orm/postgresql": 5.9.7 awilix: ^8.0.0 - bullmq: ^5.4.2 + bullmq: 5.12.0 cross-env: ^5.2.1 dotenv: ^16.4.5 ioredis: ^5.3.2 @@ -14236,9 +14236,9 @@ __metadata: languageName: node linkType: hard -"bullmq@npm:^5.4.2": - version: 5.7.8 - resolution: "bullmq@npm:5.7.8" +"bullmq@npm:5.12.0": + version: 5.12.0 + resolution: "bullmq@npm:5.12.0" dependencies: cron-parser: ^4.6.0 ioredis: ^5.4.1 @@ -14247,7 +14247,7 @@ __metadata: semver: ^7.5.4 tslib: ^2.0.0 uuid: ^9.0.0 - checksum: 49471348f6c645c58aa3105ab39a942f7537c0bbfdd3d4e9ba4c254eab941c0b3bb3301abe5dea0d19457b53661dbdb711566a34bb23d689b50bec111d9c1e98 + checksum: ade12a22c16db021385bdfab826ab64488fcfb07274df1b6269bf513d073ea8e8a812b7308027a16df3f00feaf1d2afe79c8c7c86749b44794c2a2e89e34a411 languageName: node linkType: hard