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(__namedParameters, config, singleton?)

Parameters

NameTypeDefault value
__namedParametersObjectundefined
configanyundefined
singletonbooleantrue

Defined in

services/event-bus.js:10

Properties

config_

config_: any

Defined in

services/event-bus.js:31


enRun_

enRun_: undefined | boolean

Defined in

services/event-bus.js:182


enqueue_

enqueue_: undefined | Promise<void>

Defined in

services/event-bus.js:183


redisClient_

redisClient_: any

Defined in

services/event-bus.js:51


redisSubscriber_

redisSubscriber_: any

Defined in

services/event-bus.js:52


stagedJobRepository_

stagedJobRepository_: any

Defined in

services/event-bus.js:39

Methods

createCronJob

createCronJob(eventName, data, cron, handler): void

Registers a cron job.

Parameters

NameTypeDescription
eventNamestringthe name of the event
dataanythe data to be sent with the event
cronstringthe cron pattern
handlerFunctionthe handler to call on each cron job

Returns

void

Defined in

services/event-bus.js:280


cronWorker_

cronWorker_(job): Promise<any>

Handles incoming jobs.

Parameters

NameTypeDescription
jobanyThe job object

Returns

Promise<any>

resolves to the results of the subscriber calls.

Defined in

services/event-bus.js:255


emit

emit(eventName, data, options?): BullJob

Calls all subscribers when an event occurs.

Parameters

NameTypeDescription
eventNamestringthe name of the event to be process.
dataanythe data to send to the subscriber.
optionsanyoptions to add the job with

Returns

BullJob

  • the job from our queue

Defined in

services/event-bus.js:154


enqueuer_

enqueuer_(): Promise<void>

Returns

Promise<void>

Defined in

services/event-bus.js:191


registerCronHandler_

registerCronHandler_(event, subscriber): void

Adds a function to a list of event subscribers.

Parameters

NameTypeDescription
eventstringthe event that the subscriber will listen for.
subscriberfuncthe function to be called when a certain event happens. Subscribers must return a Promise.

Returns

void

Defined in

services/event-bus.js:135


sleep

sleep(ms): Promise<any>

Parameters

NameType
msany

Returns

Promise<any>

Defined in

services/event-bus.js:175


startEnqueuer

startEnqueuer(): Promise<void>

Returns

Promise<void>

Defined in

services/event-bus.js:181


stopEnqueuer

stopEnqueuer(): Promise<void>

Returns

Promise<void>

Defined in

services/event-bus.js:186


subscribe

subscribe(event, subscriber): void

Adds a function to a list of event subscribers.

Parameters

NameTypeDescription
eventstringthe event that the subscriber will listen for.
subscriberfuncthe function to be called when a certain event happens. Subscribers must return a Promise.

Returns

void

Defined in

services/event-bus.js:98


unsubscribe

unsubscribe(event, subscriber): void

Adds a function to a list of event subscribers.

Parameters

NameTypeDescription
eventstringthe event that the subscriber will listen for.
subscriberfuncthe function to be called when a certain event happens. Subscribers must return a Promise.

Returns

void

Defined in

services/event-bus.js:116


withTransaction

withTransaction(transactionManager): EventBusService

Parameters

NameType
transactionManagerany

Returns

EventBusService

Defined in

services/event-bus.js:69


worker_

worker_(job): Promise<any>

Handles incoming jobs.

Parameters

NameTypeDescription
jobanyThe job object

Returns

Promise<any>

resolves to the results of the subscriber calls.

Defined in

services/event-bus.js:226