Sandboxing in BullMQ refers to the process where job processing is performed in a separate Node.js process for increased reliability and fault tolerance. This is beneficial because if a job processor crashes due to an error or some unhandled exception, it will not crash the main queue process.
Here's how you might implement a sandboxed worker:
const Queue = require('bullmq').Queue; const Worker = require('bullmq').Worker; // Set up your queue as usual const myQueue = new Queue('myQueue'); // create a worker with a separate Node.js process new Worker('myQueue', '/path/to/your/processor.js');
In this example, /path/to/your/processor.js
should be a file that exports a function. This function takes a job as its argument and processes it:
// /path/to/your/processor.js module.exports = async (job) => { // do something with the job data console.log(job.data); };
This function will run in a separate process due to the Worker instantiation, isolating potential crashes or heavy processing from the main queue process.
Please note that in the context of sandboxed processes, it is important to handle possible errors effectively. You should include good error handling procedures in your processing script.
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.