Socket
Socket
Sign inDemoInstall

@guivic/fastify-bull

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@guivic/fastify-bull

Fastify plugin to use easily Bull.


Version published
Weekly downloads
6
Maintainers
2
Weekly downloads
 
Created
Source

@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.

Keywords

FAQs

Package last updated on 09 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc