@better-bull-board/client

中文文档
0.2.1发布于 2026/10/31ISCTypeScriptESM + CJS构建来源已验证近 30 天下载 5088

Developer documentation for integrating Better Bull Board with your BullMQ workers.

原始使用文档
文档目录12 节
  1. Installation
  2. Usage
  3. Basic Setup
  4. Key Requirements
  5. Complete Example
  6. Advanced Features
  7. API Reference
  8. patch(processor, redis)
  9. createPinoJobLogDestination(options?)
  10. relayJobLog({ level, message })
  11. Worker
  12. Troubleshooting

@better-bull-board/client

Developer documentation for integrating Better Bull Board with your BullMQ workers.

Installation

pnpm add @better-bull-board/client bullmq

bullmq is a peer dependency (^6). Install the version your app uses; it does not need to match this package's pin.

Usage

To use Better Bull Board with your BullMQ workers, you need to:

  1. Import the BBB client
  2. Use a separate processor (sandboxed processor required for job cancellation)

Basic Setup

1. Create a Processor File

Create a separate processor file (e.g., processor.ts or processor.js):

import { patch } from "@better-bull-board/client"
import type { SandboxedJob } from "bullmq"

import { redis } from "./lib/redis" // Your Redis connection

export default patch(async (job: SandboxedJob) => {
  console.log(`Processing job ${job.id}`)

  // Your job processing logic here
  await processYourJob(job.data)

  console.log(`Job ${job.id} completed`)

  return { status: "done" }
}, redis)

2. Create a Worker

Use the Better Bull Board Worker class in your main worker file:

import path from "node:path"

import { Worker } from "@better-bull-board/client"

import { redis } from "./lib/redis" // Your Redis connection

const processorFile = path.join(__dirname, "processor.cjs") // Note: .cjs extension for built files

new Worker("your-queue-name", processorFile, {
  connection: redis,
  ioredis: redis,
  useWorkerThreads: true,
  concurrency: 10,
  getJobTags(job) {
    // Optional: Return tags for better organization
    return ["your-queue", "production"]
  },
})

Key Requirements

  • Separate Processor: You must use a sandboxed processor (separate file) for job cancellation to work properly
  • Redis Connection: Provide both connection and ioredis options pointing to the same Redis instance
  • Worker Threads: Set useWorkerThreads: true for proper isolation
  • File Extension: Use .cjs extension for the processor file path when referencing built files

Complete Example

Here's a complete working example based on our demo:

processor.ts

import { patch } from "@better-bull-board/client"
import type { SandboxedJob } from "bullmq"

import { redis } from "../lib/redis"

export default patch(async (job: SandboxedJob) => {
  console.log(`Processing job ${job.id}`)

  // Simulate work
  await new Promise((resolve) => setTimeout(resolve, 10_000))

  console.log(`Job ${job.id} processed`)

  return { status: "done" }
}, redis)

worker.ts

import path from "node:path"
import { fileURLToPath } from "node:url"

import { Worker } from "@better-bull-board/client"

import { redis } from "./lib/redis"

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const processorFile = path.join(__dirname, "processor.cjs")

new Worker("demo-queue", processorFile, {
  connection: redis,
  ioredis: redis,
  useWorkerThreads: true,
  concurrency: 10,
  getJobTags() {
    return ["demo-queue", "test"]
  },
})

Advanced Features

Job Cancellation

The patch function provides built-in job cancellation support. Jobs can be cancelled through the Better Bull Board UI.

Job logs

All console output from your processors is automatically captured and sent to Better Bull Board for monitoring.

Loggers that write to stdout directly, like pino, bypass console. Give pino the job log destination so each line also reaches the current job:

import { createPinoJobLogDestination } from "@better-bull-board/client"
import { pino } from "pino"

export const logger = pino(
  { level: "info" },
  pino.multistream([
    { stream: process.stdout, level: "trace" },
    { stream: createPinoJobLogDestination({ ignore: ["trace_id"] }), level: "trace" },
  ]),
)

The destination keeps msg, appends the other fields as JSON and prints err like a thrown error, followed by its own fields (code, data, …); ignore drops keys you do not want in the job logs (pid and hostname already are). Outside a job it is a no-op, so one logger instance serves both the worker and its processors.

Any other logger can call relayJobLog({ level, message }) from its transport: it forwards the line to the job bound to the current async context and does nothing otherwise.

Job Tags

Use the getJobTags function to organize and filter your jobs in the Better Bull Board interface:

getJobTags(job) {
  return [
    job.queueName,
    job.data.priority || "normal",
    process.env.NODE_ENV || "development"
  ];
}

API Reference

patch(processor, redis)

Wraps your job processor with Better Bull Board functionality.

  • processor: Your async job processing function
  • redis: Redis connection instance

createPinoJobLogDestination(options?)

A pino destination that relays each log line to the current job's logs.

  • options.ignore: extra keys to drop from the relayed message

relayJobLog({ level, message })

Forwards one log line to the job bound to the current async context, if any. level is one of log, debug, info, warn, error.

Worker

Extended BullMQ Worker with Better Bull Board integration.

Required Options:

  • ioredis: Redis connection instance
  • useWorkerThreads: Must be true
  • getJobTags: Optional function to return job tags

Troubleshooting

  • Job cancellation not working: Ensure you're using a sandboxed processor (separate file)
  • Jobs not appearing: Check that your Redis connection is properly configured
  • Build issues: Make sure to reference .cjs files for built processors

版本与发布记录

@better-bull-board/client 共发布 27 个版本,首次发布于 2025/09/29;过去 12 个月发布了 12 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.1latest2026/10/318 天前
0.2.02026/10/2910 天前
0.1.92026/10/2712 天前
0.1.82026/10/1029 天前
0.1.72026/09/151 个月前
0.1.62026/09/022 个月前

关于 @better-bull-board/client 的常见问题

@better-bull-board/client 是什么?

Developer documentation for integrating Better Bull Board with your BullMQ workers.

如何安装 @better-bull-board/client?

在项目目录运行 npm install @better-bull-board/client,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:bullmq(^6.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@better-bull-board/client 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@better-bull-board/client 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@better-bull-board/client 可以商用吗?

@better-bull-board/client 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@better-bull-board/client 的下载量有多少?

根据 npm 官方下载统计,@better-bull-board/client 在 2026/10/08 – 2026/11/06 这 30 天内被下载 5,088 次,日均约 170 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@better-bull-board/client 还在维护吗?

最新版本 0.2.1 发布于 2026/10/31(8 天前);至今共发布 27 个版本,其中过去 12 个月发布了 12 个;首次发布于 2025/09/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。