0

How to serialize jobs in job queue of BullMQ? I need that the next job is scheduled for execution only when the previous job is finished. I am using BullMQ 3.

Vitaly
  • 1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Apr 14 '22 at 21:42

1 Answers1

0

You can use the FlowProducer to create this type of behaviour.

An example would be:

const flowProducer = new FlowProducer({connection: {
        host: "host_here",
        port: 6379
    }});

    const jobChain = await flowProducer.add({
        name:'example',
        data: { field: 'value'},
        "queueName",
        children: [{
            name: 'example2', //can be same/different name
            data: {field: 'otherValue'},
            "queueName", // can be a different queuename
            children: ...
        }],
    });

Here the the "example" job would only be executed when "example2" is successfully processed. This has to do with both the FlowProducer behaviour & general understanding of the job lifecycle.

Lifecycle info: https://docs.bullmq.io/guide/architecture

Flows info: https://docs.bullmq.io/guide/flows

  • I need a queue, in which I can dynamically add any number of tasks and they should be executed sequentially. Lets say there are 3 tasks in the queue and they are processed one by one. Then I push the fourth task. It should be executed after the third task and so on. In case of Flow producer, there are only two levels, children tasks and parent task. When children tasks are completed, parent task is executed. – Vitaly Jul 06 '22 at 09:44