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:75
Properties
config_
• Protected
Readonly
config_: ConfigModule
Defined in
packages/medusa/src/services/event-bus.ts:59
enqueue_
• Protected
enqueue_: Promise
<void
>
Defined in
packages/medusa/src/services/event-bus.ts:73
eventToSubscribersMap_
• Protected
Readonly
eventToSubscribersMap_: Map
<string
| symbol
, SubscriberDescriptor
[]>
Defined in
packages/medusa/src/services/event-bus.ts:64
jobSchedulerService_
• Protected
Readonly
jobSchedulerService_: default
Defined in
packages/medusa/src/services/event-bus.ts:63
logger_
• Protected
Readonly
logger_: Logger
Defined in
packages/medusa/src/services/event-bus.ts:61
manager_
• Protected
Readonly
manager_: EntityManager
Defined in
packages/medusa/src/services/event-bus.ts:60
queue_
• Protected
queue_: Bull
Defined in
packages/medusa/src/services/event-bus.ts:70
redisClient_
• Protected
Readonly
redisClient_: Redis
Defined in
packages/medusa/src/services/event-bus.ts:68
redisSubscriber_
• Protected
Readonly
redisSubscriber_: Redis
Defined in
packages/medusa/src/services/event-bus.ts:69
shouldEnqueuerRun
• Protected
shouldEnqueuerRun: boolean
Defined in
packages/medusa/src/services/event-bus.ts:71
stagedJobRepository_
• Protected
Readonly
stagedJobRepository_: typeof StagedJobRepository
Defined in
packages/medusa/src/services/event-bus.ts:62
transactionManager_
• Protected
transactionManager_: undefined
| EntityManager
Defined in
packages/medusa/src/services/event-bus.ts:72
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:421
emit
▸ 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:225
enqueuer_
▸ enqueuer_(): Promise
<void
>
Returns
Promise
<void
>
Defined in
packages/medusa/src/services/event-bus.ts:285
startEnqueuer
▸ startEnqueuer(): void
Returns
void
Defined in
packages/medusa/src/services/event-bus.ts:275
stopEnqueuer
▸ stopEnqueuer(): Promise
<void
>
Returns
Promise
<void
>
Defined in
packages/medusa/src/services/event-bus.ts:280
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:155
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:198
withTransaction
▸ withTransaction(transactionManager
): EventBusService
Parameters
Name | Type |
---|---|
transactionManager | any |
Returns
Defined in
packages/medusa/src/services/event-bus.ts:123
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.