jimenezmaximiliano / very-simple-queue

Very Simple Queue is a job queue with a simple API and support for sqlite3, redis and mysql

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Very Simple Queue

CI

Very Simple Queue is a job queue with a simple API and support for:

  • redis
  • mysql
  • sqlite3

Installation

npm install very-simple-queue

or

yarn add very-simple-queue

Usage

Instantiating the VerySimpleQueue facade

const VerySimpleQueue = require('very-simple-queue');

const verySimpleQueue = new VerySimpleQueue('sqlite3', {
  filePath: '/tmp/testdb.sqlite3',
});

Usage example

await verySimpleQueue.createJobsDbStructure(); // Only the first time
await verySimpleQueue.pushJob({ obladi: "oblada" }, 'myQueue');
await verySimpleQueue.handleJob((payload) => console.log(payload), 'myQueue');

Workers

Using the work function

await verySimpleQueue.work((payload) => console.log(payload), { queue: 'myQueue' });
Default values for worker settings
{
  queue: 'default',
  restTimeInSeconds: 5,
  logResults: false,
  limit: null, // Number of jobs to handle before stopping
  logErrors: false,
  stopOnFailure: false,
  loggerFunction: console.log,
}
Graceful shutdown

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.

Other functions

Handle job by UUID

await verySimpleQueue.handleJobByUuid((payload) => console.log(payload), 'myQueue', 'uuid');

Custom workers

You can create custom workers using the provided functions to handle jobs. You only need a loop.

License

ISC

About

Very Simple Queue is a job queue with a simple API and support for sqlite3, redis and mysql

License:ISC License


Languages

Language:JavaScript 97.1%Language:Shell 2.9%