Socket
Book a DemoInstallSign in
Socket

@opens/bullmq

Package Overview
Dependencies
Maintainers
4
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opens/bullmq

A wrapper around bullmq

1.0.11
latest
npmnpm
Version published
Weekly downloads
52
-17.46%
Maintainers
4
Weekly downloads
 
Created
Source

BullMQWrapper

BullMQWrapper is a wrapper around BullMQ that simplifies creating and managing task queues using Redis. It provides an easy interface for queue creation, worker registration, and task publishing.

Usage

Install

On top of installing this package, the following variables must be defined in your environment or an exception will be thrown

BULLMQ_REDIS_HOST BULLMQ_REDIS_PORT

Creating a Task Queue

To create a queue, you can use createTask. You can specify the queue name, job options, and an optional worker to process jobs.


import { bullmq } from '@opens/bullmq';

bullmq.createTask({
  taskName: 'example-task',
  concurrency: 5,
  up: async (data, job) => {
    console.log('Processing job:', job.id);
  },
});

Publishing a Task

Once the queue is created, you can add tasks to it using publishTask.

await bullmq.publishTask({
  taskName: 'example-task',
  taskData: { key: 'value' },
  taskOptions: { delay: 1000 },
});

Creating a Worker

Workers process jobs in the queue. You can create a worker separately using createWorker.

bullmq.createWorker({
  taskName: 'example-task',
  concurrency: 3,
  up: async (data, job) => {
    console.log('Job executed:', job.data);
  },
  down: async (data, job, error) => {
    console.log('Job failed::', job.id);
    console.error("With error::", error)
  },
});

Getting Task Count

To check the number of active queues, use getTaskCount.

console.log('Number of task queues:', bullmq.getTaskCount());

Error Handling

  • If a task queue does not exist, publishTask returns null.
  • If a worker fails, you can define a down function to handle failures.

License

This project is licensed under the MIT License.

FAQs

Package last updated on 01 Apr 2025

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.