Agent skill

Bullmq

by zhe-qi in zhe-qi/clhoria-template

创建或修改 BullMQ 队列任务。当需要创建新队列、添加任务类型、注册 Worker、设置定时任务、或用户请求"添加后台任务/队列处理"时使用

MITAuto-check passed

Install Bullmq

skills CLI
$ npx skills add zhe-qi/clhoria-template --skill bullmq -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install zhe-qi/clhoria-template bullmq --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/zhe-qi/clhoria-template.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/bullmq .claude/skills/bullmq && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
bullmq
GitHub stars
193
Token cost
~1.6k tokens
SKILL.md length
347 words
Files
6
Skills in repo
10
Repo updated
First seen
Licence
MIT

At a glance

创建或修改 BullMQ 队列任务。当需要创建新队列、添加任务类型、注册 Worker、设置定时任务、或用户请求"添加后台任务/队列处理"时使用

  • Works in 5 steps: 添加新队列 → 添加新任务类型 → 注册 Worker → …
  • Tasks that involve Background jobs
  • SKILL.md covers 技术栈, 文件结构, 核心规则(MANDATORY) and 开发步骤, plus 6 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Bullmq is an agent skill from zhe-qi/clhoria-template. 创建或修改 BullMQ 队列任务。当需要创建新队列、添加任务类型、注册 Worker、设置定时任务、或用户请求"添加后台任务/队列处理"时使用

Its SKILL.md is about 1.6k tokens, which your agent loads only when the skill is triggered. The skill folder holds 7 other files (for example `examples/email-cleanup-queues.md`, `templates/job-definition.md` and `templates/queue-definition.md`).

It works with Zod and Hono. The repository describes itself as: Production-ready Hono backend template that doubles as an AI agent harness — providing feedforward guides, feedback sensors, and progressive specialization to make AI coding… The licence is MIT.

When your agent uses it

  • Tasks that involve Background jobs

Example prompts

  • “添加后台任务/队列处理”
  • “/bullmq”

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. 添加新队列
  2. 添加新任务类型
  3. 注册 Worker
  4. 添加任务到队列
  5. 设置定时任务

What it can do on your machine

Read from SKILL.md and the folder at commit 589f13e. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are typescript).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Bullmq loads about 1.6k tokens when it runs. Until then it costs about 20 tokens; SKILL.md has 347 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~20
When it runs · the whole SKILL.md, loaded when a task matches
~1.6k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from zhe-qi/clhoria-template at commit 589f13e, republished under its MIT licence (© zhe-qi). 347 words, ~1,630 tokens.

Download SKILL.mdSave it as .claude/skills/bullmq/SKILL.md (or your agent's skills folder). This skill also uses 5 other files; get the full folder from GitHub.
name
bullmq
description
创建或修改 BullMQ 队列任务。当需要创建新队列、添加任务类型、注册 Worker、设置定时任务、或用户请求"添加后台任务/队列处理"时使用
argument-hint
[queue-name/job-name]

BullMQ 队列任务开发指南

技术栈

  • 队列系统: BullMQ v5.16.0+
  • 类型安全: TypeScript + Zod 运行时验证
  • Effect 集成: Effect 系统封装(Promise → Effect)
  • Redis: ioredis (maxRetriesPerRequest: null)
  • UI 监控: Bull Board (Hono adapter)

文件结构

src/lib/
├── enums/bullmq.ts                      # 队列和任务名称枚举
├── infrastructure/
│   ├── bullmq/
│   │   └── job-registry.ts              # 类型映射和 Zod 验证
│   ├── bullmq-adapter.ts                # QueueManager 核心类
│   └── effect/services/bullmq.ts        # Effect Layer
│   └── bootstrap.ts                     # Worker 注册位置
src/routes/admin/
└── queue-board.index.ts                 # Bull Board UI 路由

核心规则(MANDATORY)

三层类型安全架构
  1. 编译时约束:QueueJobsMapping 确保队列只能使用特定 job name
  2. 类型推断:JobDefinitionRegistry 自动推断 job data 类型
  3. 运行时验证:JobSchemaRegistry 使用 Zod 验证数据
命名约定
  • 队列名称:小写字母(email、cleanup,不用 EMAIL_QUEUE)
  • 任务名称:kebab-case(send-welcome、daily-cleanup)
  • 常量枚举:对象字面量 + as const(不用 enum)
  • 索引签名:[JobName.XXX]: Schema 形式
数据验证规则
  • 所有 job data 必须有对应的 Zod schema
  • Schema 必须包含中文错误消息
  • 日期格式:ISO 8601 字符串(2024-01-01T00:00:00Z)
  • 日期字符串:YYYY-MM-DD 格式
  • UUID:使用 z.uuid() 验证
Effect 使用规范
  • 所有异步操作使用 Effect 封装(Effect.tryPromise)
  • 同步操作使用 Effect.sync
  • 错误统一返回 Error 类型
  • Worker 注册使用 Effect.sync(立即返回 Worker 实例)

开发步骤

1. 添加新队列

参考 queue-definition.md

  1. 在 src/lib/enums/bullmq.ts 添加队列名称
  2. 在 job-registry.ts 创建 QueueJobsMapping 映射(初始为 never)
  3. 注册 Worker(见步骤 3)
2. 添加新任务类型

参考 job-definition.md

  1. 在 src/lib/enums/bullmq.ts 添加任务名称
  2. 在 job-registry.ts 创建 Zod schema
  3. 更新 JobDefinitionRegistry 类型映射
  4. 更新 JobSchemaRegistry 验证映射
  5. 更新 QueueJobsMapping 关联队列
3. 注册 Worker

参考 worker-registration.md

  1. 在应用启动时调用 queueManager.registerWorker
  2. 实现 processor 函数(接收 Job<T> 类型)
  3. 可选配置:并发数、限流、重试策略
  4. Worker 自动验证 job data(无需手动验证)
4. 添加任务到队列

在业务代码中使用(无需创建文件):

typescript
import { Effect } from "effect";
import { queueManager } from "@/lib/infrastructure/bullmq-adapter";
import { JobName, QueueName } from "@/lib/enums/bullmq";

// 添加任务
const program = queueManager.addJob(
  QueueName.EMAIL,
  JobName.EMAIL_SEND_WELCOME,
  { email: "user@example.com", username: "testuser" },
  { priority: 1, delay: 5000 }, // 可选配置
);

await Effect.runPromise(program);
5. 设置定时任务

参考 scheduled-job.md

使用 Job Schedulers API(BullMQ v5.16.0+):

typescript
// 调度定时任务
const program = queueManager.scheduleJob(
  QueueName.CLEANUP,
  JobName.CLEANUP_DAILY,
  {},
  { pattern: "0 0 * * *" }, // Cron 表达式
);

await Effect.runPromise(program);

// 移除定时任务
await Effect.runPromise(
  queueManager.unscheduleJob(QueueName.CLEANUP, JobName.CLEANUP_DAILY),
);

模板参考

队列和任务定义

参考 queue-definition.md

包含:

  • QueueName 枚举定义
  • JobName 枚举定义
  • 命名规范
Job Registry 类型映射

参考 job-definition.md

包含:

  • Zod schema 定义(含验证规则)
  • JobDefinitionRegistry 类型映射
  • JobSchemaRegistry 验证映射
  • QueueJobsMapping 队列关联
Worker 注册

参考 worker-registration.md

包含:

  • Worker 注册位置(bootstrap.ts)
  • Processor 函数实现
  • Worker 配置选项
  • 错误处理
定时任务设置

参考 scheduled-job.md

包含:

  • Cron 表达式语法
  • 调度和移除定时任务
  • 查询已调度任务
  • 定时任务最佳实践

完整示例

参考 examples/email-cleanup-queues.md 查看完整的 Email 和 Cleanup 队列实现。

关键 API

QueueManager 核心方法
typescript
// 添加任务(Effect 封装 + Zod 验证)
addJob<Q, N>(
  queueName: Q,
  jobName: N,
  data: JobDataByName<N>,
  opts?: JobsOptions,
): Effect<Job>

// 注册 Worker(Effect 封装)
registerWorker<Q>(
  queueName: Q,
  processor: (job: Job) => Promise<any>,
  options?: WorkerOptions,
): Effect<Worker>

// 调度定时任务(Effect 封装 + Zod 验证)
scheduleJob<Q, N>(
  queueName: Q,
  jobName: N,
  data: JobDataByName<N>,
  repeatOptions: RepeatOptions,
): Effect<void>

// 移除定时任务
unscheduleJob(queueName: string, jobName: string): Effect<boolean>

// 查询定时任务
getScheduledJobs(queueName: string): Effect<JobScheduler[]>

// 获取队列实例(用于 Bull Board)
getQueue(name: string): Queue

// 优雅关闭
close(timeoutMs?: number): Effect<void>

最佳实践

DO: 推荐做法
  • 使用类型安全的 addJob 和 registerWorker 方法
  • 所有 job data 定义 Zod schema 并添加中文错误消息
  • Worker processor 中使用结构化日志(logger.info({ jobId, ... }, "[Queue]: message"))
  • 定时任务使用明确的 cron 表达式(带注释)
  • Worker 配置合理的并发数和重试策略
  • 长时间运行的任务设置 timeout
DON'T: 避免做法
  • 不要使用 getQueue 直接添加任务(绕过类型检查和验证)
  • 不要在 job data 中传递大对象(使用引用 ID)
  • 不要在 Worker 中使用 console.log(使用 logger)
  • 不要忘记在 QueueJobsMapping 中关联队列和任务
  • 不要修改已有 job 的 schema(创建新版本)
  • 不要在 processor 中抛出未捕获异常(使用 try-catch)

集成点

与 Effect 系统集成
typescript
import { BullMQService } from "@/lib/infrastructure/effect/services/bullmq";

const program = Effect.gen(function* () {
  const qm = yield* BullMQService;
  yield* qm.addJob(QueueName.EMAIL, JobName.EMAIL_SEND_WELCOME, data);
});
与 db-schema 配合使用

定时任务可能需要查询数据库:

typescript
import { subDays } from "date-fns";
import { lt } from "drizzle-orm";
import db from "@/db";
import { auditLogs } from "@/db/schema";

// Worker processor 中
const processor = async (job: Job<CleanupData>) => {
  const { daysToKeep } = job.data;

  const cutoffDate = subDays(new Date(), daysToKeep);

  await db
    .delete(auditLogs)
    .where(lt(auditLogs.createdAt, cutoffDate.toISOString()));

  logger.info({ daysToKeep }, "[Cleanup]: 旧日志已清理");
};
Bull Board 监控

访问 /api/admin/queue-board 查看:

  • 队列状态(waiting/active/completed/failed)
  • 任务详情和重试
  • Worker 性能指标
  • 定时任务调度器

常见问题

Worker 何时注册?

在应用启动时(src/lib/infrastructure/bootstrap.ts)注册所有 Worker。

如何处理失败的任务?

BullMQ 自动重试(默认 3 次)。Worker 可配置:

typescript
registerWorker(queueName, processor, {
  attempts: 5,
  backoff: { type: "exponential", delay: 2000 },
});
定时任务如何避免重复?

使用 scheduleJob(内部调用 upsertJobScheduler),相同 schedulerId 会覆盖。

如何测试队列逻辑?

参考 src/lib/infrastructure/__tests__/bullmq-adapter.test.ts:

  • 测试类型安全(编译时)
  • 测试运行时验证(Zod)
  • 测试 Worker processor 逻辑
  • 测试定时任务调度

重要提醒

  • BullMQ Worker 需要专用 Redis 连接(maxRetriesPerRequest: null)
  • QueueManager 是 Singleton,自动在 shutdown 时销毁
  • Worker 注册是幂等的(重复注册返回同一个实例)
  • 定时任务使用 Job Schedulers API(v5.16.0+),不是 Repeatable Jobs
  • Bull Board 动态获取队列(无需手动注册)

© zhe-qi, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 5 other files in .agents/skills/bullmq of zhe-qi/clhoria-template.

  • SKILL.md
  • examples/email-cleanup-queues.md
  • templates/job-definition.md
  • templates/queue-definition.md
  • templates/scheduled-job.md
  • templates/worker-registration.md

Open the folder on GitHubat commit 589f13e

Compare with similar skills

Bullmq next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Bullmq compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Bullmq this skillzhe-qi/clhoria-template193—~1.6kAutomated safety check: PassMIT
Trigger.dev Background Taskspapermark/papermark9.2k—~2.1kAutomated safety check: PassCustom licence
Upstash Workflow Patternslobehub/lobehub83k—~1.7kAutomated safety check: PassCustom licence
Mastra Honojwynia/agent-skills170—~2.9kAutomated safety check: PassMIT
Hono Idiomsirahardianto/awesome-agv156—~3kAutomated safety check: PassMIT
Backend ExpertCaoMeiYouRen/caomei-auth220—~329Automated safety check: PassMIT

Similar skills

  • Trigger.dev Background Tasks

    papermark/papermark

    Guides building durable background tasks, scheduled jobs and queues with Trigger.dev, including retries, waits, idempotency and concurrency limits.

    9.2k GitHub stars~2.1k tokensUpdated 1 mo ago
    Backend & APIsAuto-check passed
  • Implementation patterns for Upstash Workflow and QStash handlers in the LobeHub codebase: dry runs, fan-out chunking and single-item execution.

    83k GitHub stars~1.7k tokensUpdated today
    Backend & APIsAuto-check passed
  • Mastra Hono

    jwynia/agent-skills

    Develop AI agents, tools, and workflows with Mastra v1 Beta and Hono servers.

    170 GitHub stars~2.9k tokensUpdated 7 mo ago
    Frontend & DesignAuto-check passed
  • Hono Idioms

    irahardianto/awesome-agv

    Hono lightweight web framework patterns: type-safe route handlers, middleware composition, Zod validation, and RPC clients for Cloudflare Workers, Node, or Bun.

    156 GitHub stars~3k tokensUpdated 6 days ago
    DevelopmentAuto-check passed
  • Backend Expert

    CaoMeiYouRen/caomei-auth

    设计或实现后端 API、服务层、数据库读写、鉴权权限控制、输入校验、事务处理与错误处理时使用。用户提到 API、route、handler、server、auth、permission、drizzle、database、zod、Hono、Nuxt server routes、backend bug 修复时都应触发。

    220 GitHub stars~329 tokensUpdated 10 days ago
    DatabasesAuto-check passed
  • Hono Helper

    shepherdjerred/monorepo

    Hono web framework for edge-first, lightweight APIs - routing, middleware, validation, and multi-runtime support When user works with Hono, builds APIs, creates middleware, uses Zod validation with…

    112 GitHub stars~4.3k tokensUpdated yesterday
    Frontend & DesignAuto-check passed

More from zhe-qi/clhoria-template

All 10 skills in this repo
  • Effect V4

    zhe-qi/clhoria-template

    Effect v4 模式指南。当需要创建 Effect 服务、定义错误类型、编写 Effect 程序、管理 Layer 组合、或使用 Effect 封装异步操作时使用

    193 GitHub stars~887 tokensUpdated 2 mo ago
    Auto-check passed
  • Create Tier

    zhe-qi/clhoria-template

    创建或修改一个新的 API tier。当用户请求“新增 tier / 创建 partner tier / 新增 merchant 端 / 新增 tenant 端 / 新增 API 端 / 新增一套路由层”时使用。目标是在不修改框架核心的前提下,为新 tier 补齐配置、中间件、类型别名、路由入口和测试。

    193 GitHub stars~1.7k tokensUpdated 2 mo ago
    Auto-check: notes
  • Crud

    zhe-qi/clhoria-template

    创建或修改 CRUD 模块。当需要创建新的增删改查 API、修改现有路由模块、添加新字段、新增接口、或用户请求"创建/修改 XX 管理"时使用

    193 GitHub stars~552 tokensUpdated 2 mo ago
    Auto-check passed
  • DB Schema

    zhe-qi/clhoria-template

    创建或修改数据库 Schema。当需要创建新表、修改表结构、定义字段、设置索引约束、或涉及 Drizzle ORM / drizzle-zod 操作时使用

    193 GitHub stars~620 tokensUpdated 2 mo ago
    Auto-check passed
  • Drizzle V1

    zhe-qi/clhoria-template

    Drizzle ORM v1 关系查询指南。当需要定义 Relations v2、编写关系查询、使用 through 多对多、预定义过滤器、或从旧版 Drizzle 迁移时使用

    193 GitHub stars~3k tokensUpdated 2 mo ago
    Auto-check passed
  • Source Command Opsx Explore

    zhe-qi/clhoria-template

    Enter explore mode - think through ideas, investigate problems, clarify requirements

    193 GitHub stars~1.6k tokensUpdated 2 mo ago
    Auto-check passed

Works with

Questions about Bullmq

What does Bullmq do?

创建或修改 BullMQ 队列任务。当需要创建新队列、添加任务类型、注册 Worker、设置定时任务、或用户请求"添加后台任务/队列处理"时使用. Bullmq is an agent skill from zhe-qi/clhoria-template.

When should I use Bullmq?

Bullmq fits situations like: tasks that involve Background jobs.

How do I install Bullmq in Claude Code?

Run `npx skills add zhe-qi/clhoria-template --skill bullmq -a claude-code`. Or copy the skill folder (.agents/skills/bullmq in zhe-qi/clhoria-template) into .claude/skills/bullmq in your project. Claude Code loads it when a task matches its description.

How do I install Bullmq in Codex?

Run `npx skills add zhe-qi/clhoria-template --skill bullmq -a codex`. Or copy the skill folder (.agents/skills/bullmq in zhe-qi/clhoria-template) into .agents/skills/bullmq in your project. Codex loads it when a task matches its description.

Can I use Bullmq in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add zhe-qi/clhoria-template --skill bullmq -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/bullmq, .gemini/skills/bullmq, .github/skills/bullmq and .opencode/skills/bullmq in your project.

What does Bullmq need to run?

SKILL.md names no scripts, command-line tools or credentials: Bullmq is instructions for the agent only.

Does Bullmq access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Bullmq safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Bullmq use?

Bullmq is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Bullmq use?

About 1.6k tokens (SKILL.md is roughly 6.5k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Bullmq?

Skills that share tags, products or a category with Bullmq: Trigger.dev Background Tasks (papermark/papermark, 9.2k stars), Upstash Workflow Patterns (lobehub/lobehub, 83k stars), Mastra Hono (jwynia/agent-skills, 170 stars) and Hono Idioms (irahardianto/awesome-agv, 156 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Bullmq?

zhe-qi (a GitHub user) maintains it in zhe-qi/clhoria-template, which has 193 GitHub stars. The repository holds 10 skills in this directory. The repository was last updated on July 30, 2026.

Source: zhe-qi/clhoria-template on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.