Switch branches/tags
moleculer-twilio@1.0.10 moleculer-twilio@1.0.9 moleculer-twilio@1.0.8 moleculer-twilio@1.0.7 moleculer-twilio@1.0.6 moleculer-twilio@1.0.5 moleculer-twilio@1.0.4 moleculer-twilio@1.0.3 moleculer-twilio@1.0.2 moleculer-twilio@1.0.1 moleculer-twilio@1.0.0 moleculer-slack@1.1.0 moleculer-slack@1.0.0 moleculer-mail@1.2.1 moleculer-mail@1.2.0 moleculer-mail@1.1.1 moleculer-mail@1.1.0 moleculer-mail@1.0.8 moleculer-mail@1.0.7 moleculer-mail@1.0.6 moleculer-mail@1.0.5 moleculer-mail@1.0.4 moleculer-mail@1.0.3 moleculer-mail@1.0.2 moleculer-mail@1.0.1 moleculer-mail@1.0.0 moleculer-fake@1.0.12 moleculer-fake@1.0.11 moleculer-fake@1.0.10 moleculer-fake@1.0.9 moleculer-fake@1.0.8 moleculer-fake@1.0.7 moleculer-fake@1.0.6 moleculer-fake@1.0.5 moleculer-fake@1.0.4 moleculer-fake@1.0.3 moleculer-fake@1.0.2 moleculer-fake@1.0.1 moleculer-fake@1.0.0 moleculer-elasticsearch@1.1.1 moleculer-elasticsearch@1.1.0 moleculer-elasticsearch@1.0.6 moleculer-elasticsearch@1.0.5 moleculer-elasticsearch@1.0.4 moleculer-elasticsearch@1.0.3 moleculer-elasticsearch@1.0.2 moleculer-elasticsearch@1.0.1 moleculer-elasticsearch@1.0.0 moleculer-db@0.6.3 moleculer-db@0.6.2 moleculer-db@0.6.1 moleculer-db@0.6.0 moleculer-db@0.5.2 moleculer-db@0.5.1 moleculer-db@0.5.0 moleculer-db@0.4.5 moleculer-db@0.4.4 moleculer-db@0.4.3 moleculer-db@0.4.2 moleculer-db@0.4.1 moleculer-db@0.4.0 moleculer-db@0.3.3 moleculer-db@0.3.2 moleculer-db@0.3.1 moleculer-db@0.3.0 moleculer-db@0.2.0 moleculer-db@0.1.3 moleculer-db@0.1.2 moleculer-db@0.1.1 moleculer-db@0.1.0 moleculer-db-adapter-sequelize@0.1.4 moleculer-db-adapter-sequelize@0.1.3 moleculer-db-adapter-sequelize@0.1.2 moleculer-db-adapter-sequelize@0.1.1 moleculer-db-adapter-sequelize@0.1.0 moleculer-db-adapter-mongoose@0.4.4 moleculer-db-adapter-mongoose@0.4.3 moleculer-db-adapter-mongoose@0.4.2 moleculer-db-adapter-mongoose@0.4.1 moleculer-db-adapter-mongoose@0.4.0 moleculer-db-adapter-mongoose@0.3.1 moleculer-db-adapter-mongoose@0.3.0 moleculer-db-adapter-mongoose@0.2.0 moleculer-db-adapter-mongoose@0.1.2 moleculer-db-adapter-mongoose@0.1.1 moleculer-db-adapter-mongoose@0.1.0 moleculer-db-adapter-mongo@0.1.4 moleculer-db-adapter-mongo@0.1.3 moleculer-db-adapter-mongo@0.1.2 moleculer-db-adapter-mongo@0.1.1 moleculer-db-adapter-mongo@0.1.0 moleculer-bull@0.2.2 moleculer-bull@0.2.1 moleculer-bull@0.2.0 moleculer-bull@0.1.8 moleculer-bull@0.1.7 moleculer-bull@0.1.6 moleculer-bull@0.1.5 moleculer-bull@0.1.4 moleculer-bull@0.1.3
Nothing to show
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
..
Failed to load latest commit information.
examples
src
test/unit
.gitignore
CHANGELOG.md
LICENSE
README.md
index.js
package-lock.json
package.json

README.md

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 queue worker service with concurrency and named jobs

const QueueService = require("moleculer-bull");

broker.createService({
    name: "task-worker",
    mixins: [QueueService()],

    queues: {
        "mail.send": {
            name: 'important',
            concurrency: 5,
            process(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(payload) {
            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);
            });
        }
    }
});

Create named job in service

const QueueService = require("moleculer-bull");

broker.createService({
    name: "job-maker",
    mixins: [QueueService()],

    methods: {
        sendEmail(payload) {
            this.createJob("mail.send", "important", 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-2018 MoleculerJS

@moleculerjs @MoleculerJS