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 | Object | undefined |
config | any | undefined |
singleton | boolean | true |
Defined in
Properties
config_
• config_: any
Defined in
enRun_
• enRun_: undefined
| boolean
Defined in
enqueue_
• enqueue_: undefined
| Promise
<void
>
Defined in
redisClient_
• redisClient_: any
Defined in
redisSubscriber_
• redisSubscriber_: any
Defined in
stagedJobRepository_
• stagedJobRepository_: any
Defined in
Methods
createCronJob
▸ createCronJob(eventName
, data
, cron
, handler
): void
Registers a cron job.
Parameters
Name | Type | Description |
---|---|---|
eventName | string | the name of the event |
data | any | the data to be sent with the event |
cron | string | the cron pattern |
handler | Function | the handler to call on each cron job |
Returns
void
Defined in
cronWorker_
▸ cronWorker_(job
): Promise
<any
>
Handles incoming jobs.
Parameters
Name | Type | Description |
---|---|---|
job | any | The job object |
Returns
Promise
<any
>
resolves to the results of the subscriber calls.
Defined in
emit
▸ emit(eventName
, data
, options?
): BullJob
Calls all subscribers when an event occurs.
Parameters
Name | Type | Description |
---|---|---|
eventName | string | the name of the event to be process. |
data | any | the data to send to the subscriber. |
options | any | options to add the job with |
Returns
BullJob
- the job from our queue
Defined in
enqueuer_
▸ enqueuer_(): Promise
<void
>
Returns
Promise
<void
>
Defined in
registerCronHandler_
▸ registerCronHandler_(event
, subscriber
): void
Adds a function to a list of event subscribers.
Parameters
Name | Type | Description |
---|---|---|
event | string | the event that the subscriber will listen for. |
subscriber | func | the function to be called when a certain event happens. Subscribers must return a Promise. |
Returns
void
Defined in
sleep
▸ sleep(ms
): Promise
<any
>
Parameters
Name | Type |
---|---|
ms | any |
Returns
Promise
<any
>
Defined in
startEnqueuer
▸ startEnqueuer(): Promise
<void
>
Returns
Promise
<void
>
Defined in
stopEnqueuer
▸ stopEnqueuer(): Promise
<void
>
Returns
Promise
<void
>
Defined in
subscribe
▸ subscribe(event
, subscriber
): void
Adds a function to a list of event subscribers.
Parameters
Name | Type | Description |
---|---|---|
event | string | the event that the subscriber will listen for. |
subscriber | func | the function to be called when a certain event happens. Subscribers must return a Promise. |
Returns
void
Defined in
unsubscribe
▸ unsubscribe(event
, subscriber
): void
Adds a function to a list of event subscribers.
Parameters
Name | Type | Description |
---|---|---|
event | string | the event that the subscriber will listen for. |
subscriber | func | the function to be called when a certain event happens. Subscribers must return a Promise. |
Returns
void
Defined in
withTransaction
▸ withTransaction(transactionManager
): EventBusService
Parameters
Name | Type |
---|---|
transactionManager | any |
Returns
Defined in
worker_
▸ worker_(job
): Promise
<any
>
Handles incoming jobs.
Parameters
Name | Type | Description |
---|---|---|
job | any | The job object |
Returns
Promise
<any
>
resolves to the results of the subscriber calls.