node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

moleculer-bull

Moleculer logo

moleculer-bull NPM version

Task queue mixin for Bull.

Install

$ npm install moleculer-bull --save

Usage

Create queue worker service

const QueueService = require("moleculer-bull");
 
broker.createService({
    name: "task-worker",
    mixins: [QueueService()],
 
    queues: {
        "mail.send"(job) {
            this.logger.info("New job received!", job.data);
            job.progress(10);
 
            return this.Promise.resolve({
                done: true,
                id: job.data.id,
                worker: process.pid
            });
        }
    }
});

Create job in service

const QueueService = require("moleculer-bull");
 
broker.createService({
    name: "job-maker",
    mixins: [QueueService()],
 
    methods: {
        sendEmail(data) {
            this.createJob("mail.send", payload);
 
            this.getQueue("mail.send").on("global:progress", (jobID, progress) => {
                this.logger.info(`Job #${jobID} progress is ${progress}%`);
            });
 
            this.getQueue("mail.send").on("global:completed", (job, res) => {
                this.logger.info(`Job #${job.id} completed!. Result:`, res);
            });
        }
    }
});

Test

$ npm test

In development with watching

$ npm run ci

License

The project is available under the MIT license.

Contact

Copyright (c) 2016-2017 Ice Services

@ice-services @MoleculerJS