feat: make it possible to use subscribers in v2 (#6731)
This commit is contained in:
1 parent
db9c460490
commit
873c21355c
8 files changed
+39
-27
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(medusa): make subscribers work in v2
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
"@medusajs/modules-sdk": "^1.12.8",
|
"@medusajs/modules-sdk": "^1.12.8",
|
||||||
"@medusajs/utils": "^1.11.5",
|
"@medusajs/utils": "^1.11.5",
|
||||||
"awilix": "^8.0.0",
|
"awilix": "^8.0.0",
|
||||||
"bullmq": "^3.5.6",
|
"bullmq": "^5.4.2",
|
||||||
"ioredis": "^5.2.5"
|
"ioredis": "^5.2.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -296,7 +296,7 @@ describe("RedisEventBusService", () => {
|
|||||||
completedSubscriberIds: ["1"],
|
completedSubscriberIds: ["1"],
|
||||||
},
|
},
|
||||||
attemptsMade: 2,
|
attemptsMade: 2,
|
||||||
update: (data) => data,
|
updateData: (data) => data,
|
||||||
opts: { attempts: 3 },
|
opts: { attempts: 3 },
|
||||||
})
|
})
|
||||||
.catch((err) => void 0)
|
.catch((err) => void 0)
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ export default class RedisEventBusService extends AbstractEventBusModuleService
|
|||||||
|
|
||||||
job.data.completedSubscriberIds = updatedCompletedSubscribers
|
job.data.completedSubscriberIds = updatedCompletedSubscribers
|
||||||
|
|
||||||
await job.update(job.data)
|
await job.updateData(job.data)
|
||||||
|
|
||||||
const errorMessage = `One or more subscribers of ${eventName} failed. Retrying...`
|
const errorMessage = `One or more subscribers of ${eventName} failed. Retrying...`
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@
|
|||||||
"awilix": "^8.0.0",
|
"awilix": "^8.0.0",
|
||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
"boxen": "^5.0.1",
|
"boxen": "^5.0.1",
|
||||||
"bullmq": "^3.5.6",
|
"bullmq": "^5.4.2",
|
||||||
"chokidar": "^3.4.2",
|
"chokidar": "^3.4.2",
|
||||||
"class-transformer": "^0.5.1",
|
"class-transformer": "^0.5.1",
|
||||||
"class-validator": "^0.14.0",
|
"class-validator": "^0.14.0",
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||||
import { MedusaContainer, Subscriber } from "@medusajs/types"
|
import { MedusaContainer, Subscriber } from "@medusajs/types"
|
||||||
import { kebabCase } from "@medusajs/utils"
|
import { kebabCase } from "@medusajs/utils"
|
||||||
import { readdir } from "fs/promises"
|
import { readdir } from "fs/promises"
|
||||||
@@ -15,6 +16,7 @@ type SubscriberModule<T> = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class SubscriberLoader {
|
export class SubscriberLoader {
|
||||||
|
protected isV2_: boolean
|
||||||
protected container_: MedusaContainer
|
protected container_: MedusaContainer
|
||||||
protected pluginOptions_: Record<string, unknown>
|
protected pluginOptions_: Record<string, unknown>
|
||||||
protected activityId_: string
|
protected activityId_: string
|
||||||
@@ -32,12 +34,14 @@ export class SubscriberLoader {
|
|||||||
rootDir: string,
|
rootDir: string,
|
||||||
container: MedusaContainer,
|
container: MedusaContainer,
|
||||||
options: Record<string, unknown> = {},
|
options: Record<string, unknown> = {},
|
||||||
activityId: string
|
activityId: string,
|
||||||
|
isV2: boolean = false
|
||||||
) {
|
) {
|
||||||
this.rootDir_ = rootDir
|
this.rootDir_ = rootDir
|
||||||
this.pluginOptions_ = options
|
this.pluginOptions_ = options
|
||||||
this.container_ = container
|
this.container_ = container
|
||||||
this.activityId_ = activityId
|
this.activityId_ = activityId
|
||||||
|
this.isV2_ = isV2
|
||||||
}
|
}
|
||||||
|
|
||||||
private validateSubscriber(
|
private validateSubscriber(
|
||||||
@@ -181,8 +185,10 @@ export class SubscriberLoader {
|
|||||||
config: SubscriberConfig
|
config: SubscriberConfig
|
||||||
handler: SubscriberHandler<T>
|
handler: SubscriberHandler<T>
|
||||||
}) {
|
}) {
|
||||||
const eventBusService: EventBusService =
|
const resName = this.isV2_
|
||||||
this.container_.resolve("eventBusService")
|
? ModuleRegistrationName.EVENT_BUS
|
||||||
|
: "eventBusService"
|
||||||
|
const eventBusService: EventBusService = this.container_.resolve(resName)
|
||||||
|
|
||||||
const { event } = config
|
const { event } = config
|
||||||
|
|
||||||
|
|||||||
@@ -177,7 +177,8 @@ async function registerSubscribers(
|
|||||||
path.join(pluginDetails.resolve, "subscribers"),
|
path.join(pluginDetails.resolve, "subscribers"),
|
||||||
container,
|
container,
|
||||||
pluginDetails.options,
|
pluginDetails.options,
|
||||||
activityId
|
activityId,
|
||||||
|
true
|
||||||
).load()
|
).load()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8209,7 +8209,7 @@ __metadata:
|
|||||||
"@medusajs/types": ^1.11.12
|
"@medusajs/types": ^1.11.12
|
||||||
"@medusajs/utils": ^1.11.5
|
"@medusajs/utils": ^1.11.5
|
||||||
awilix: ^8.0.0
|
awilix: ^8.0.0
|
||||||
bullmq: ^3.5.6
|
bullmq: ^5.4.2
|
||||||
cross-env: ^5.2.1
|
cross-env: ^5.2.1
|
||||||
ioredis: ^5.2.5
|
ioredis: ^5.2.5
|
||||||
jest: ^29.6.3
|
jest: ^29.6.3
|
||||||
@@ -8488,7 +8488,7 @@ __metadata:
|
|||||||
awilix: ^8.0.0
|
awilix: ^8.0.0
|
||||||
body-parser: ^1.19.0
|
body-parser: ^1.19.0
|
||||||
boxen: ^5.0.1
|
boxen: ^5.0.1
|
||||||
bullmq: ^3.5.6
|
bullmq: ^5.4.2
|
||||||
chokidar: ^3.4.2
|
chokidar: ^3.4.2
|
||||||
class-transformer: ^0.5.1
|
class-transformer: ^0.5.1
|
||||||
class-validator: ^0.14.0
|
class-validator: ^0.14.0
|
||||||
@@ -22283,22 +22283,6 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"bullmq@npm:^3.5.6":
|
|
||||||
version: 3.15.8
|
|
||||||
resolution: "bullmq@npm:3.15.8"
|
|
||||||
dependencies:
|
|
||||||
cron-parser: ^4.6.0
|
|
||||||
glob: ^8.0.3
|
|
||||||
ioredis: ^5.3.2
|
|
||||||
lodash: ^4.17.21
|
|
||||||
msgpackr: ^1.6.2
|
|
||||||
semver: ^7.3.7
|
|
||||||
tslib: ^2.0.0
|
|
||||||
uuid: ^9.0.0
|
|
||||||
checksum: e41429c526ec44c24891cc4533fb34e358a6ad996a001b14869b7495189c47395f9539def423e3a950f5e11a43711fdcea73592994a6387a7fcbf720d76b0442
|
|
||||||
languageName: node
|
|
||||||
linkType: hard
|
|
||||||
|
|
||||||
"bullmq@npm:^5.1.3":
|
"bullmq@npm:^5.1.3":
|
||||||
version: 5.1.3
|
version: 5.1.3
|
||||||
resolution: "bullmq@npm:5.1.3"
|
resolution: "bullmq@npm:5.1.3"
|
||||||
@@ -22316,6 +22300,22 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"bullmq@npm:^5.4.2":
|
||||||
|
version: 5.4.2
|
||||||
|
resolution: "bullmq@npm:5.4.2"
|
||||||
|
dependencies:
|
||||||
|
cron-parser: ^4.6.0
|
||||||
|
ioredis: ^5.3.2
|
||||||
|
lodash: ^4.17.21
|
||||||
|
msgpackr: ^1.10.1
|
||||||
|
node-abort-controller: ^3.1.1
|
||||||
|
semver: ^7.5.4
|
||||||
|
tslib: ^2.0.0
|
||||||
|
uuid: ^9.0.0
|
||||||
|
checksum: 01687a41bbacb646ab9cac181181c0cf18362f23b250c332125e0a701dacefb48ff20b030e095f24bd5e471f29d514bcc02779fd1f1c3cb830a3a5f1d0a39d75
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"bundle-name@npm:^3.0.0":
|
"bundle-name@npm:^3.0.0":
|
||||||
version: 3.0.0
|
version: 3.0.0
|
||||||
resolution: "bundle-name@npm:3.0.0"
|
resolution: "bundle-name@npm:3.0.0"
|
||||||
@@ -39253,7 +39253,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"msgpackr@npm:^1.5.4, msgpackr@npm:^1.6.2":
|
"msgpackr@npm:^1.5.4":
|
||||||
version: 1.9.5
|
version: 1.9.5
|
||||||
resolution: "msgpackr@npm:1.9.5"
|
resolution: "msgpackr@npm:1.9.5"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|||||||
Reference in new issue
Block a user