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(__namedParameters
, config
, singleton?
)
Parameters
Name | Type | Default value |
---|---|---|
__namedParameters | InjectedDependencies | undefined |
config | ConfigModule | undefined |
singleton | boolean | true |
Defined in
packages/medusa/src/services/event-bus.ts:80
Properties
config_
• Protected
Readonly
config_: ConfigModule
Defined in
packages/medusa/src/services/event-bus.ts:64
enqueue_
• Protected
enqueue_: Promise
<void
>
Defined in
packages/medusa/src/services/event-bus.ts:78
eventToSubscribersMap_
• Protected
Readonly
eventToSubscribersMap_: Map
<string
| symbol
, SubscriberDescriptor
[]>
Defined in
packages/medusa/src/services/event-bus.ts:69
jobSchedulerService_
• Protected
Readonly
jobSchedulerService_: default
Defined in
packages/medusa/src/services/event-bus.ts:68
logger_
• Protected
Readonly
logger_: Logger
Defined in
packages/medusa/src/services/event-bus.ts:66
manager_
• Protected
Readonly
manager_: EntityManager
Defined in
packages/medusa/src/services/event-bus.ts:65
queue_
• Protected
queue_: Bull
Defined in
packages/medusa/src/services/event-bus.ts:75
redisClient_
• Protected
Readonly
redisClient_: Redis
Defined in
packages/medusa/src/services/event-bus.ts:73
redisSubscriber_
• Protected
Readonly
redisSubscriber_: Redis
Defined in
packages/medusa/src/services/event-bus.ts:74
shouldEnqueuerRun
• Protected
shouldEnqueuerRun: boolean
Defined in
packages/medusa/src/services/event-bus.ts:76
stagedJobRepository_
• Protected
Readonly
stagedJobRepository_: typeof StagedJobRepository
Defined in
packages/medusa/src/services/event-bus.ts:67
transactionManager_
• Protected
transactionManager_: undefined
| EntityManager
Defined in
packages/medusa/src/services/event-bus.ts:77
Methods
createCronJob
▸ createCronJob<T
>(eventName
, data
, cron
, handler
, options?
): Promise
<void
>
Registers a cron job.
Deprecated
All cron job logic has been refactored to the JobSchedulerService
. This method will be removed in a future release.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
eventName | string | the name of the event |
data | T | the data to be sent with the event |
cron | string | the cron pattern |
handler | Subscriber <unknown > | the handler to call on each cron job |
options? | CreateJobOptions | - |
Returns
Promise
<void
>
void
Defined in
packages/medusa/src/services/event-bus.ts:463
emit
▸ emit<T
>(data
): Promise
<void
| StagedJob
[]>
Calls all subscribers when an event occurs.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
data | EmitData <T >[] | The data to use to process the events |
Returns
Promise
<void
| StagedJob
[]>
the jobs from our queue
Defined in
packages/medusa/src/services/event-bus.ts:228
▸ emit<T
>(eventName
, data
, options?
): Promise
<void
| StagedJob
>
Calls all subscribers when an event occurs.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
eventName | string | the name of the event to be process. |
data | T | the data to send to the subscriber. |
options? | any | options to add the job with |
Returns
Promise
<void
| StagedJob
>
the job from our queue
Defined in
packages/medusa/src/services/event-bus.ts:237
enqueuer_
▸ enqueuer_(): Promise
<void
>
Returns
Promise
<void
>
Defined in
packages/medusa/src/services/event-bus.ts:324
startEnqueuer
▸ startEnqueuer(): void
Returns
void
Defined in
packages/medusa/src/services/event-bus.ts:314
stopEnqueuer
▸ stopEnqueuer(): Promise
<void
>
Returns
Promise
<void
>
Defined in
packages/medusa/src/services/event-bus.ts:319
subscribe
▸ subscribe(event
, subscriber
, context?
): EventBusService
Adds a function to a list of event subscribers.
Parameters
Name | Type | Description |
---|---|---|
event | string | symbol | the event that the subscriber will listen for. |
subscriber | Subscriber <unknown > | the function to be called when a certain event |
context? | SubscriberContext | context to use when attaching subscriber happens. Subscribers must return a Promise. |
Returns
this
Defined in
packages/medusa/src/services/event-bus.ts:160
unsubscribe
▸ unsubscribe(event
, subscriber
): EventBusService
Adds a function to a list of event subscribers.
Parameters
Name | Type | Description |
---|---|---|
event | string | symbol | the event that the subscriber will listen for. |
subscriber | Subscriber <unknown > | the function to be called when a certain event happens. Subscribers must return a Promise. |
Returns
this
Defined in
packages/medusa/src/services/event-bus.ts:203
withTransaction
▸ withTransaction(transactionManager
): EventBusService
Parameters
Name | Type |
---|---|
transactionManager | any |
Returns
Defined in
packages/medusa/src/services/event-bus.ts:128
worker_
▸ worker_<T
>(job
): Promise
<unknown
>
Handles incoming jobs.
Type parameters
Name |
---|
T |
Parameters
Name | Type | Description |
---|---|---|
job | BullJob <T > | The job object |
Returns
Promise
<unknown
>
resolves to the results of the subscriber calls.