Skip to content

DbQueuesRouterPg

do- edited this page Aug 19, 2024 · 14 revisions

DbQueuesRouterPg is a companion object to DbListenerPg routing incoming notifications to DbQueue instances.

Constructor

const ch = new DbQueuesRouterPg (app, {
   name: 'QR',
// test: (dbNotificationPg) => true,
// on: {
//  'job-end': job => doSomething (job.result)
//  'job-error': [
//    job => reportOnce (job.error),
//    job => reportTwice (job.error),
//  ],
//},
})

Parameters

Name Description
app an Application instance.
options a bag of options (see below)

Options

Name Type Default Description
name String the name, for logging
test DbNotificationPg => Boolean ()=>true the test selector see Router for details
on Object {} a bag of JobSource events handlers

Properties

listener and models properties below are set while plugging this instance into some DbListenerPg by calling its .add () method.

Name Description
app The Application this instance is bound to
listener The DbListenerPg this instance is attached to
models Set of DbModels of all DbPoolPg from the app.pools connected to the same database as the listener

Methods

getQueue (notification)

Returns a DbQueue instance based on the notification value or throws an Error if none is found.

In the base implementation, scans this.models trying to finds the queue by getQueueName (notification) as name.

getQueueName (notification)

Returns a supposed DbViewQueuePg name based on the notification value.

In the base implementation, returns notification.payload if it's a non empty string, otherwise, throws an Error.

registerQueue (queue)

This method is called for each DbQueue found in the model when the listener property is set (normally, by calling .add ()).

In the base implementation, it copies handlers from this.on to the target queue and then calls its .check ().

[Router.PROCESS_MESSAGE] (notification)

Invokes getQueue (notification), then calls its result's check () method.

Clone this wiki locally