mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 13:27:08 +00:00
28 lines
835 B
JavaScript
28 lines
835 B
JavaScript
const { listen } = require('../lib/db/notify');
|
|
const channels = require('../lib/db/channels');
|
|
const handlers = require('./handlers').init();
|
|
const { ERROR, INFO, DEBUG } = require('DOUGAL_ROOT/debug')(__filename);
|
|
|
|
function start () {
|
|
listen(channels, async function (data) {
|
|
DEBUG("Incoming data", data);
|
|
for (const handler of handlers) {
|
|
// NOTE: We are intentionally passing the same instance
|
|
// of the data to every handler. This means that earlier
|
|
// handlers could, in principle, modify the data to be
|
|
// consumed by latter ones, provided that they are
|
|
// synchronous (as otherwise, the completion order is
|
|
// undefined).
|
|
await handler.run(data);
|
|
}
|
|
});
|
|
|
|
INFO("Events manager started.", handlers.length, "active handlers");
|
|
}
|
|
|
|
module.exports = { start }
|
|
|
|
if (require.main === module) {
|
|
start();
|
|
}
|