Skip to main content

Class: EventBusService

Can keep track of multiple subscribers to different events and run the subscribers when events happen. Events will run asynchronously.

Constructors

constructor

new EventBusService(__namedParametersCopy to Clipboard, configCopy to Clipboard, singleton?Copy to Clipboard)

Parameters

NameTypeDefault value
__namedParametersCopy to ClipboardInjectedDependenciesCopy to ClipboardundefinedCopy to Clipboard
configCopy to ClipboardConfigModuleCopy to ClipboardundefinedCopy to Clipboard
singletonCopy to ClipboardbooleanCopy to ClipboardtrueCopy to Clipboard

Defined in

packages/medusa/src/services/event-bus.ts:80

Properties

config_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard config_: ConfigModuleCopy to Clipboard

Defined in

packages/medusa/src/services/event-bus.ts:64


enqueue_

ProtectedCopy to Clipboard enqueue_: PromiseCopy to Clipboard<voidCopy to Clipboard>

Defined in

packages/medusa/src/services/event-bus.ts:78


eventToSubscribersMap_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard eventToSubscribersMap_: MapCopy to Clipboard<stringCopy to Clipboard | symbolCopy to Clipboard, SubscriberDescriptorCopy to Clipboard[]>

Defined in

packages/medusa/src/services/event-bus.ts:69


jobSchedulerService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard jobSchedulerService_: defaultCopy to Clipboard

Defined in

packages/medusa/src/services/event-bus.ts:68


logger_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard logger_: LoggerCopy to Clipboard

Defined in

packages/medusa/src/services/event-bus.ts:66


manager_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard manager_: EntityManagerCopy to Clipboard

Defined in

packages/medusa/src/services/event-bus.ts:65


queue_

ProtectedCopy to Clipboard queue_: BullCopy to Clipboard

Defined in

packages/medusa/src/services/event-bus.ts:75


redisClient_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard redisClient_: RedisCopy to Clipboard

Defined in

packages/medusa/src/services/event-bus.ts:73


redisSubscriber_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard redisSubscriber_: RedisCopy to Clipboard

Defined in

packages/medusa/src/services/event-bus.ts:74


shouldEnqueuerRun

ProtectedCopy to Clipboard shouldEnqueuerRun: booleanCopy to Clipboard

Defined in

packages/medusa/src/services/event-bus.ts:76


stagedJobRepository_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard stagedJobRepository_: typeof StagedJobRepositoryCopy to Clipboard

Defined in

packages/medusa/src/services/event-bus.ts:67


transactionManager_

ProtectedCopy to Clipboard transactionManager_: undefinedCopy to Clipboard | EntityManagerCopy to Clipboard

Defined in

packages/medusa/src/services/event-bus.ts:77

Methods

createCronJob

createCronJob<TCopy to Clipboard>(eventNameCopy to Clipboard, dataCopy to Clipboard, cronCopy to Clipboard, handlerCopy to Clipboard, options?Copy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Registers a cron job.

DeprecatedCopy to Clipboard

All cron job logic has been refactored to the JobSchedulerServiceCopy to Clipboard. This method will be removed in a future release.

Type parameters

Name
TCopy to Clipboard

Parameters

NameTypeDescription
eventNameCopy to ClipboardstringCopy to Clipboardthe name of the event
dataCopy to ClipboardTCopy to Clipboardthe data to be sent with the event
cronCopy to ClipboardstringCopy to Clipboardthe cron pattern
handlerCopy to ClipboardSubscriberCopy to Clipboard<unknownCopy to Clipboard>the handler to call on each cron job
options?Copy to ClipboardCreateJobOptionsCopy to Clipboard-

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

void

Defined in

packages/medusa/src/services/event-bus.ts:463


emit

emit<TCopy to Clipboard>(dataCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard | StagedJobCopy to Clipboard[]>

Calls all subscribers when an event occurs.

Type parameters

Name
TCopy to Clipboard

Parameters

NameTypeDescription
dataCopy to ClipboardEmitDataCopy to Clipboard<TCopy to Clipboard>[]The data to use to process the events

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard | StagedJobCopy to Clipboard[]>

the jobs from our queue

Defined in

packages/medusa/src/services/event-bus.ts:228

emit<TCopy to Clipboard>(eventNameCopy to Clipboard, dataCopy to Clipboard, options?Copy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard | StagedJobCopy to Clipboard>

Calls all subscribers when an event occurs.

Type parameters

Name
TCopy to Clipboard

Parameters

NameTypeDescription
eventNameCopy to ClipboardstringCopy to Clipboardthe name of the event to be process.
dataCopy to ClipboardTCopy to Clipboardthe data to send to the subscriber.
options?Copy to ClipboardanyCopy to Clipboardoptions to add the job with

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard | StagedJobCopy to Clipboard>

the job from our queue

Defined in

packages/medusa/src/services/event-bus.ts:237


enqueuer_

enqueuer_(): PromiseCopy to Clipboard<voidCopy to Clipboard>

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

Defined in

packages/medusa/src/services/event-bus.ts:324


startEnqueuer

startEnqueuer(): voidCopy to Clipboard

Returns

voidCopy to Clipboard

Defined in

packages/medusa/src/services/event-bus.ts:314


stopEnqueuer

stopEnqueuer(): PromiseCopy to Clipboard<voidCopy to Clipboard>

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

Defined in

packages/medusa/src/services/event-bus.ts:319


subscribe

subscribe(eventCopy to Clipboard, subscriberCopy to Clipboard, context?Copy to Clipboard): EventBusServiceCopy to Clipboard

Adds a function to a list of event subscribers.

Parameters

NameTypeDescription
eventCopy to ClipboardstringCopy to Clipboard | symbolCopy to Clipboardthe event that the subscriber will listen for.
subscriberCopy to ClipboardSubscriberCopy to Clipboard<unknownCopy to Clipboard>the function to be called when a certain event
context?Copy to ClipboardSubscriberContextCopy to Clipboardcontext to use when attaching subscriber happens. Subscribers must return a Promise.

Returns

EventBusServiceCopy to Clipboard

this

Defined in

packages/medusa/src/services/event-bus.ts:160


unsubscribe

unsubscribe(eventCopy to Clipboard, subscriberCopy to Clipboard): EventBusServiceCopy to Clipboard

Adds a function to a list of event subscribers.

Parameters

NameTypeDescription
eventCopy to ClipboardstringCopy to Clipboard | symbolCopy to Clipboardthe event that the subscriber will listen for.
subscriberCopy to ClipboardSubscriberCopy to Clipboard<unknownCopy to Clipboard>the function to be called when a certain event happens. Subscribers must return a Promise.

Returns

EventBusServiceCopy to Clipboard

this

Defined in

packages/medusa/src/services/event-bus.ts:203


withTransaction

withTransaction(transactionManagerCopy to Clipboard): EventBusServiceCopy to Clipboard

Parameters

NameType
transactionManagerCopy to ClipboardanyCopy to Clipboard

Returns

EventBusServiceCopy to Clipboard

Defined in

packages/medusa/src/services/event-bus.ts:128


worker_

worker_<TCopy to Clipboard>(jobCopy to Clipboard): PromiseCopy to Clipboard<unknownCopy to Clipboard>

Handles incoming jobs.

Type parameters

Name
TCopy to Clipboard

Parameters

NameTypeDescription
jobCopy to ClipboardBullJobCopy to Clipboard<TCopy to Clipboard>The job object

Returns

PromiseCopy to Clipboard<unknownCopy to Clipboard>

resolves to the results of the subscriber calls.

Defined in

packages/medusa/src/services/event-bus.ts:362