Very Simple Queue is a job queue with a simple API and support for:
- redis
- mysql
- sqlite3
npm install very-simple-queue
or
yarn add very-simple-queue
const VerySimpleQueue = require('very-simple-queue');
const verySimpleQueue = new VerySimpleQueue('sqlite3', {
filePath: '/tmp/testdb.sqlite3',
});
await verySimpleQueue.createJobsDbStructure(); // Only the first time
await verySimpleQueue.pushJob({ obladi: "oblada" }, 'myQueue');
await verySimpleQueue.handleJob((payload) => console.log(payload), 'myQueue');
await verySimpleQueue.work((payload) => console.log(payload), { queue: 'myQueue' });
{
queue: 'default',
restTimeInSeconds: 5,
logResults: false,
limit: null, // Number of jobs to handle before stopping
logErrors: false,
stopOnFailure: false,
loggerFunction: console.log,
}
After getting a signal to shut down your application, you can stop workers to grab another job like this:
verySimpleQueue.shutdown();
Existing jobs will be finished.
await verySimpleQueue.handleJobByUuid((payload) => console.log(payload), 'myQueue', 'uuid');
You can create custom workers using the provided functions to handle jobs. You only need a loop.