mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 09:47:08 +00:00
The events listener now uses a proper self-consuming queue and the event handlers have been rewritten accordingly. The way this works is that running init() on the handlers library instantiates the handlers and returns two higher-order functions, prepare() and despatch(). A call to the latter of these is appended to the queue with each new incoming event. The handlers have access to a context object (ctx) which may be used to persist data between calls and/or exchange data between handlers. This is used notably to give the handlers access to project configurations, which are themselves refreshed by a project configuration change handler (DetectProjectConfigurationChange).
30 lines
699 B
JavaScript
30 lines
699 B
JavaScript
const { listen } = require('../lib/db/notify');
|
|
const channels = require('../lib/db/channels');
|
|
const handlers = require('./handlers');
|
|
const { ActionsQueue } = require('../lib/queue');
|
|
const { ERROR, INFO, DEBUG } = require('DOUGAL_ROOT/debug')(__filename);
|
|
|
|
function start () {
|
|
|
|
const queue = new ActionsQueue();
|
|
const ctx = {}; // Context object
|
|
|
|
const { prepare, despatch } = handlers.init(ctx);
|
|
|
|
listen(channels, function (data) {
|
|
DEBUG("Incoming data", data);
|
|
|
|
// We don't bother awaiting
|
|
queue.enqueue(() => despatch(data, ctx));
|
|
DEBUG("Queue size", queue.length());
|
|
});
|
|
|
|
INFO("Events manager started");
|
|
}
|
|
|
|
module.exports = { start }
|
|
|
|
if (require.main === module) {
|
|
start();
|
|
}
|