chore: workflow internals improvementss (#9455)
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
import { EventBusTypes } from "@medusajs/types"
|
||||
import {
|
||||
EventBusTypes,
|
||||
InternalModuleDeclaration,
|
||||
MedusaContainer,
|
||||
} from "@medusajs/types"
|
||||
import { ulid } from "ulid"
|
||||
|
||||
export abstract class AbstractEventBusModuleService
|
||||
implements EventBusTypes.IEventBusModuleService
|
||||
{
|
||||
protected isWorkerMode: boolean = true
|
||||
|
||||
protected eventToSubscribersMap_: Map<
|
||||
string | symbol,
|
||||
EventBusTypes.SubscriberDescriptor[]
|
||||
@@ -16,6 +22,14 @@ export abstract class AbstractEventBusModuleService
|
||||
return this.eventToSubscribersMap_
|
||||
}
|
||||
|
||||
protected constructor(
|
||||
container: MedusaContainer,
|
||||
moduleOptions = {},
|
||||
moduleDeclaration: InternalModuleDeclaration
|
||||
) {
|
||||
this.isWorkerMode = moduleDeclaration.worker_mode !== "server"
|
||||
}
|
||||
|
||||
abstract emit<T>(
|
||||
data: EventBusTypes.Message<T> | EventBusTypes.Message<T>[],
|
||||
options: Record<string, unknown>
|
||||
@@ -63,6 +77,10 @@ export abstract class AbstractEventBusModuleService
|
||||
subscriber: EventBusTypes.Subscriber,
|
||||
context?: EventBusTypes.SubscriberContext
|
||||
): this {
|
||||
if (!this.isWorkerMode) {
|
||||
return this
|
||||
}
|
||||
|
||||
if (typeof subscriber !== `function`) {
|
||||
throw new Error("Subscriber must be a function")
|
||||
}
|
||||
@@ -88,6 +106,10 @@ export abstract class AbstractEventBusModuleService
|
||||
subscriber: EventBusTypes.Subscriber,
|
||||
context: EventBusTypes.SubscriberContext
|
||||
): this {
|
||||
if (!this.isWorkerMode) {
|
||||
return this
|
||||
}
|
||||
|
||||
if (typeof subscriber !== `function`) {
|
||||
throw new Error("Subscriber must be a function")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user