moleculer-bee-queue
Task queue mixin for Bee-Queue.
Install
$ npm install moleculer-bee-queue --save
Usage
Create queue worker service
const QueueService = require("moleculer-bee-queue");
broker.createService({
name: "task-worker",
mixins: [QueueService()],
queues: {
"mail.send"(job) {
this.logger.info("New job received!", job.data);
job.reportProgress(10);
return this.Promise.resolve({
done: true,
id: job.data.id,
worker: process.pid
});
}
}
});
Create job in service
const QueueService = require("moleculer-bee-queue");
broker.createService({
name: "job-maker",
mixins: [QueueService()],
methods: {
sendEmail(data) {
const job = this.createJob("mail.send", payload);
job.on("progress", progress => {
this.logger.info(`Job #${job.id} progress is ${progress}%`);
});
job.on("succeeded", res => {
this.logger.info(`Job #${job.id} completed!. Result:`, res);
});
job.retries(2).save();
}
}
});
Test
$ npm test
In development with watching
$ npm run ci
License
The project is available under the MIT license.
Contact
Copyright (c) 2016-2019 MoleculerJS