Я хочу обрабатывать запланированные задания с помощью node.js bull. В основном у меня есть два процессора, которые обрабатывают 2 типа заданий. Есть один конфигуратор, который настраивает задания, которые будут добавлены в бычью очередь с помощью cron.
Планировщик будет в одном микросервисе, а каждый процессор будет отдельным микросервисом. Так что у меня будет 3 микросервиса.
У меня вопрос: правильный ли паттерн я использую с быком?
index.js
const Queue = require('bull');
const fetchQueue = new Queue('MyScheduler');
fetchQueue.add("fetcher", {name: "earthQuakeAlert"}, {repeat: {cron: '1-59/2 * * * *'}, removeOnComplete: true});
fetchQueue.add("fetcher", {name: "weatherAlert"}, {repeat: {cron: '3-59/3 * * * *'}, removeOnComplete: true});
processor-configurator.js
const Queue=require('bull');
const scheduler = new Queue("MyScheduler");
scheduler.process("processor", __dirname + "/alert-processor");
fetcher-configurator.js
const Queue=require('bull');
const scheduler = new Queue("MyScheduler");
scheduler.process("fetcher", __dirname+"/fetcher");
fetcher.js
const Queue = require('bull');
const moment = require('moment');
module.exports = function (job) {
const scheduler = new Queue('MyScheduler');
console.log("Insider processor ", job.data, moment().format("YYYY-MM-DD hh:mm:ss"));
scheduler.add('processor', {'name': 'Email needs to be sent'}, {removeOnComplete: true});
return Promise.resolve()
};
alert-processor.js
const Queue = require('bull');
const moment = require('moment');
module.exports = function (job) {
const scheduler = new Queue('MyScheduler');
console.log("Insider processor ", job.data, moment().format("YYYY-MM-DD hh:mm:ss"));
scheduler.add('processor', {'name': 'Email needs to be sent'}, {removeOnComplete: true});
return Promise.resolve()
};
Будет три микросервиса -
- узел index.js
- узел fetcher-configurator.js
- узел процессор-configurator.js
Я вижу непоследовательное поведение быка. Иногда я получаю сообщение об ошибке Отсутствует обработчик процесса для типа задания