2023-09-29 15:44:12 +02:00
|
|
|
const { listen } = require('../lib/db/notify');
|
2021-05-24 13:48:53 +02:00
|
|
|
const channels = require('../lib/db/channels');
|
2023-10-14 20:53:42 +02:00
|
|
|
const handlers = require('./handlers');
|
|
|
|
|
const { ActionsQueue } = require('../lib/queue');
|
2022-05-15 13:37:24 +02:00
|
|
|
const { ERROR, INFO, DEBUG } = require('DOUGAL_ROOT/debug')(__filename);
|
2020-09-28 21:36:32 +02:00
|
|
|
|
|
|
|
|
function start () {
|
2023-10-14 20:53:42 +02:00
|
|
|
|
|
|
|
|
const queue = new ActionsQueue();
|
|
|
|
|
const ctx = {}; // Context object
|
|
|
|
|
|
|
|
|
|
const { prepare, despatch } = handlers.init(ctx);
|
|
|
|
|
|
|
|
|
|
listen(channels, function (data) {
|
2022-05-15 13:37:24 +02:00
|
|
|
DEBUG("Incoming data", data);
|
2023-10-14 20:53:42 +02:00
|
|
|
|
|
|
|
|
// We don't bother awaiting
|
|
|
|
|
queue.enqueue(() => despatch(data, ctx));
|
|
|
|
|
DEBUG("Queue size", queue.length());
|
2020-09-28 21:36:32 +02:00
|
|
|
});
|
2022-04-29 14:48:21 +02:00
|
|
|
|
2023-10-14 20:53:42 +02:00
|
|
|
INFO("Events manager started");
|
2020-09-28 21:36:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = { start }
|
2020-10-02 01:34:49 +02:00
|
|
|
|
|
|
|
|
if (require.main === module) {
|
|
|
|
|
start();
|
|
|
|
|
}
|