moleculer-bee-queue

0.1.10 • Public • Published

Moleculer logo

moleculer-bee-queue NPM version

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

@moleculerjs @MoleculerJS

Readme

Keywords

Package Sidebar

Install

npm i moleculer-bee-queue

Weekly Downloads

133

Version

0.1.10

License

MIT

Unpacked Size

10.4 kB

Total Files

11

Last publish

Collaborators

  • icebob