Implementation

Our new Bull service will live in between services that can queue up jobs and ones that will do work. What we need to do now is learn how to move jobs across queues manually and expose those methods as an API other services can use.

Looking into the codebase, the methods queue.add() , queue.getNextJob() , job.moveToFailed() , and job.moveToCompleted() are all we need.

The only problem with this is that job.moveToFailed() and job.moveToCompleted() are private. It means that the authors didn’t write these methods to be used publicly.

This makes sense as Bull was never designed to do what we are trying to do. Looking into the GitHub issues in the repo, I found someone else trying to do the same thing.

The actual implementation of our new job-queue server is fairly simple now that we have these methods. Check out the docs I contributed after coming up with this new pattern.

This is exactly what I am trying to achieve, it makes me feel better someone already thought about doing this.

Before embarking on using this code in production, a great idea is to open a pull request to add documentation about this pattern. Bull is a fairly active project so the maintainer or contributors could give us good insight.