Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moleculer-Bull : defaultJobOptions for specific queue in a simple service that only create jobs #137

Open
tafel opened this issue Nov 13, 2024 · 0 comments

Comments

@tafel
Copy link

tafel commented Nov 13, 2024

I use moleculer-bull to manage multiple queues which have each different job options.

Here is a simplified setup:

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

// queues service
broker.createService({
    name: "task-worker",
    mixins: [QueueService({
        defaultJobOptions: {
            removeOnComplete: true,
            removeOnFail: true
        }
    })],

    queues: {
        "image.transform": {
            process(job) {
                // do stuff
            }
        }
        "mail.send": {
            defaultJobOptions: {
                removeOnComplete: false,
                removeOnFail: false
            },
            process(job) {
                // do stuff
            }
       }
    }
});

If a create a job inside the above service, everything is fine. image.transform queue drops all complete and fail jobs as soon as they are done.

Now I create an other service, which needs to create jobs:

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

broker.createService({
    name: "some-service",
    mixins: [QueueService()],

    methods: {
        image(payload) {
            this.createJob('image.transform', payload);
        }
        mail(payload) {
            this.createJob('mail.send', payload);
        }
    }
});

In the above service, defaultJobOptions is not defined when instanciating QueueService, so by default, jobs are always retained.. This is not what is expected for the image.transform queue.

So we can configure options in the mixin definition:

broker.createService({
    name: "some-service",
    mixins: [QueueService({
        defaultJobOptions: {
            removeOnComplete: true,
            removeOnFail: true
        }
    })],
    ....
});

The problem here is that now, the mail.send queue will drop completed and failed jobs, which is not what is expected neither.

I should define the mail.send queue inside the queues 's service prop. But this will really create the queue inside this service, which is not what I want.

Is there a way to manage this sort of usecase? I though I could simply create actions inside the task-worker service, which create jobs here. So the QueueService mixin would be set only in this service. All other services would only call actions to this one.

Any thoughts appreciated, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant