Skip to content

DbServicePg

do- edited this page Jul 15, 2024 · 9 revisions

DbServicePg is a JobSource that creates and launches jobs based on notifications incoming from a DbListenerPg.

If getQueue (notification) finds a DbQueuePg, its check () method is called.

Otherwise, a Job is produced, the raw Notification is injected as its notification field and toComplete () is launched.

When a DbServicePg gets .add ()ed to a DbListenerPg, the check () is called for every DbQueuePg found in the database's model.

const mailChannel = new DbServicePg(app, {

        name: 'mail',

	on: {
		start: function () {
			this.rq = {type: 'mail', 'action': 'send', id: this.notification.payload}
		}
	},

})

Constructor

The signature here is just like the parent class. Only the name option is added.

Options

Name Description
name what to LISTEN on

Properties

Both properties below are set when the channel is plugged into some DbListenerPg by calling its .add () method.

Name Description
listener The DbListenerPg instance this channel 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 Queue instance based on the notification value, or undefined if the notification doesn't correspond to any queue.

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

process (notification)

If getQueue (notification) returns a non-null value (thus, a Queue instance), calls its check () method.

Otherwise, creates a new Job instance, injects notification, sets event handlers and launches the execution.

Clone this wiki locally