Workerpool on steroids with Redis. Queue persistence, automatic retry.
- 🐣 - Easy to use
- ♾️ - Retry queues automatically
- 📝 - Persist queues between restarts and crashes
- 💻 - Runs in the browser and on Node.js
- 💅 - Dynamically offloads functions to a worker
- 🔥 - Handles crashed workers
- ✅ - Module written in TypeScript
It can happen that our application restarts or crashes while jobs are in progress with workerpool. This library allows for persistence so that these jobs are not lost and can be resumed.
Install via yarn
yarn add workerpool-redis
Add the Redis environment variable.
// .env
REDIS_URL=redis://:password@localhost:6379
// .env
REDIS_URL=redis://localhost:6379
Create a queue named "testing".
import { Queue } from "workerpool-redis";
const testingQueue = new Queue("testing", (foo, arg2) => {
// your code goes here
console.log(foo); // will output "bar"
return "ghostlexly";
});
Add a job
testingQueue.add(["bar", "EDF-ARGUMENT2"]);
Trigger a function when the job is complete
import { Queue } from "workerpool-redis";
const onComplete = (result) => {
// do something with the results..
console.log(result); // will output "ghostlexly"
};
const testingQueue = new Queue(
"testing",
() => {
// your code goes here
return "ghostlexly";
},
{
retryInMinutes: 1, // retry this job in 1 minute if the job is still not completed
onComplete: onComplete,
}
);