How to work on single job at a time while multiple docker containers consume from redis kue nodejs

140 Views Asked by At

I have multiple docker containers that consume jobs from the same queue of redis kue. The problem is that they work on the same jobs. My need is on of the containers work on a job and after it finish some other container work on the job after that. The order of the jobs is important.

If I can't do it in redis kue but can with other queue managers (like kafka) it will be good as well

1

There are 1 best solutions below

0
On

What i do is to keep a state machine using switch case:

var index;

function whatever (){

    if (typeof state === 'undefined') {
        state = 0;
    }

    switch (state) {
        case 0:
            // Do whatever stuff needed;
            state++;
            break;

        case 1:
            // Do whatever stuff needed;
            state++;
            break;

        // Keep adding states

        case (last):
            // Do whatever stuff needed;
            state = 0; // if you need to reset state machine
            break;

    }
}

The other thing you can do is use Async, it has been covered many times in this site