@guivic/fastify-bull

0.0.6 • Public • Published

@guivic/fastify-bull

dependencies status dev-dependencies status Node.js CI

Use bull queues from your fastify application. Utilize fastify decorators to access shared connections, logger etc.

Installation

npm install @guivic/fastify-bull --save

yarn add @guivic/fastify-bull

Usage

Queue Handler

An example queue handler.

// queues/example.queue.js

const name = 'example';
function handler(server, job, done) { // Can also be an async handler
  /* queue processing logic here */
  done()
}

module.exports = {
  name,
  handler,
};

Adding to fastify

const fastify = require('fastify');

const server = fastify();

server.register(require('fastify-bull'), {
  paths: 'queues/**/*.queue.js', // Where to look for queues files
})

const start = async () => {
  try {
    await server.listen(3000, "0.0.0.0");

    // add an item to the queue (more information on Bull documentation)
    server.queues['example'].add({ hello: 'world' }, { priority: 1 });

  } catch (err) {
    console.log(err);
    server.log.error(err);
    process.exit(1);
  }
};

start();

Adding a task to the queue

fastify.queues['my-queue'].add({ data: 'some data' });

Options

  • paths: <String | Array> specify folder where queue handlers are present.
  • redisUrl: <String> The Redis url connection.
  • onFailed: <Function> Queue handler on "failed" event (by default will log with the fastify logger)
  • onError: <Function> Queue handler on "error" event (by default will log with the fastify logger)

Informations

Bull and Heroku

I use ioredis for the Redis conneciton. It's preconfigured to share the Redis connection across queues. It's really usefull on environment like Heroku where you have connection limits.

Author

Ludovic Lérus from Guivic

Thanks to Jerry Thomas for his fork

TODO

  • Add the support of fastify-redis
  • Add the support of Redis connection Object as options
  • Find a way to let people configure the way bull will handle the redis connection
  • Add the support for nested directory
  • Add default parameters for paths
  • Remove the fast-glob dep?

License

Licensed under MIT.

Readme

Keywords

Package Sidebar

Install

npm i @guivic/fastify-bull

Weekly Downloads

3

Version

0.0.6

License

MIT

Unpacked Size

10.3 kB

Total Files

8

Last publish

Collaborators

  • guillaume-g
  • lludol