Skip to main content
Version: Next

BullMQDriver

BullMQDriver

BullMQ-based task driver for distributed task scheduling.

This driver uses BullMQ to provide robust, distributed task scheduling with Redis as the backend. It supports both cron expressions and date-based scheduling, with built-in retry mechanisms and job persistence.

Requirements: Requires the bullmq package to be installed.

Example

import { BullMQDriver } from '@commandkit/tasks/bullmq';
import { setDriver } from '@commandkit/tasks';

const driver = new BullMQDriver({
host: 'localhost',
port: 6379,
}, 'my-tasks-queue');

setDriver(driver);

Example

// With custom Redis connection options
const driver = new BullMQDriver({
host: 'redis.example.com',
port: 6379,
password: 'your-password',
tls: true,
});
Signature
class BullMQDriver implements TaskDriver {
public readonly queue: Queue;
public readonly worker: Worker;
constructor(connection: ConnectionOptions, queueName: string = 'commandkit-tasks')
create(task: TaskData) => Promise<string>;
delete(identifier: string) => Promise<void>;
setTaskRunner(runner: TaskRunner) => Promise<void>;
}

queue

property
Queue

The BullMQ queue instance for managing tasks

worker

property
Worker

The BullMQ worker instance for processing tasks

constructor

method
(connection: ConnectionOptions, queueName: string = 'commandkit-tasks') => BullMQDriver

Creates a new BullMQ driver instance.

create

method
(task: TaskData) => Promise<string>

Creates a new scheduled task in BullMQ.

For cron tasks, this creates a repeating job with the specified cron pattern. For date tasks, this creates a delayed job that executes at the specified time.

delete

method
(identifier: string) => Promise<void>

Deletes a scheduled task from BullMQ.

This removes the job and all its children (for repeating jobs) from the queue.

setTaskRunner

method
(runner: TaskRunner) => Promise<void>

Sets the task execution runner function.

This function will be called by the BullMQ worker when a job is due for execution.