@haatlabs-core/queue

中文文档
0.18.5发布于 2026/11/14Apache-2.0TypeScriptESM + CJS近 30 天下载 5643

BullMQ work queues on Redis: publisher, retrying consumer and outbox relay.

原始使用文档
文档目录3 节
  1. Install
  2. Polling without holding a worker slot
  3. Delayed and de-duplicated publishes

@haatlabs-core/queue

BullMQ work queues on Redis: the publisher, the retrying consumer (with a priority lane) and the outbox relay. A project supplies its topology, meaning its queue names, the routing-key prefixes each takes, and its key prefix, through its own connectQueue:

const route = routeByPrefix<QueueName>({ 'shopify-sync': ['shopify.'], imports: ['import.'] });
export const connectQueue = (url: string, options: { prefix?: string } = {}) =>
  connect(url, { prefix: options.prefix ?? 'shop:queue', route });

ioredis is a peer dependency.

@haatlabs-core/queue/contracts (0.12.1): QUEUE_ERRORS, QueueErrorCode, createQueueError and the QueueError type, with nothing of Node: a project's contracts, which its pages load, import from here and never the root, which is for Node.

Install

pnpm add @haatlabs-core/queue

It leaves one package to your app, so the app holds one copy: ioredis.

Polling without holding a worker slot

A handler that waits on something external (a bulk operation, media processing) calls pollAgain(message, { delayMs, deadlineMs, state, onDeadline }). The job is put back as a delayed job, its worker slot is free meanwhile, it keeps its attempt count and its lane, and message.poll (round, startedAt, deadlineAt, state) is there on the next round.

  • delayMs is 250 ms to 15 min a round. Every poll has a deadline, set on the first round and shared by all later rounds and phases; a round can shorten it, never extend it. Once it has passed, onDeadline() is thrown and the job fails.
  • Each round runs the handler again from the top. The work before pollAgain must be idempotent, or branch on message.poll.state.
  • state is JSON of at most 16 KiB; more is a RangeError.
  • onDeadline()'s error decides what happens next: a transient one fails the attempt and the retry starts the flow afresh (the poll is cleared); a permanent one keeps the job as failed. A PollAgain thrown directly past the deadline fails as POLL_TIMED_OUT (QUEUE_ERRORS), which is transient.
  • RestartPoll fails the attempt as transient and clears the poll, so the retry starts afresh.
  • A poll round is logged at debug and its queue.process span ends with outcome poll, not as an error.

Delayed and de-duplicated publishes

publish(key, payload, { delayMs, deduplication: { id } }) delays a message, or coalesces the publishes that share an id. The job holds the id until it completes or fails for good:

  • waiting for its first run (delayed or not), a later publish is dropped: the job has not started, so it will see the newer state;
  • running, the newest later publish is kept and queued when it finishes or fails;
  • delayed again, by a PollAgain round or a retry's backoff, a later publish is dropped, though the job has already read the state.

So use deduplication only for handlers that never poll and recompute from scratch on every attempt. The consumer warns, once a poll, when a de-duplicated job polls.

Such publishes are direct, never through the outbox: an outbox row carries no delayMs and no deduplication. If the process dies between the commit and the publish, the message is lost. A caller that needs it to survive publishes through the outbox, without them, and coalesces in the handler instead.

Failed jobs are kept 1,000 per queue for 14 days.

版本与发布记录

@haatlabs-core/queue 共发布 27 个版本,首次发布于 2026/10/23;过去 12 个月发布了 27 个版本。

版本发布日期距今
0.18.5latest2026/11/143 天前
0.18.42026/11/133 天前
0.18.32026/11/134 天前
0.18.22026/11/134 天前
0.18.12026/11/134 天前
0.18.02026/11/134 天前

关于 @haatlabs-core/queue 的常见问题

@haatlabs-core/queue 是什么?

BullMQ work queues on Redis: publisher, retrying consumer and outbox relay.

如何安装 @haatlabs-core/queue?

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

@haatlabs-core/queue 支持 TypeScript 吗?

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

@haatlabs-core/queue 支持 ESM 还是 CommonJS?

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

@haatlabs-core/queue 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@haatlabs-core/queue 可以商用吗?

@haatlabs-core/queue 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@haatlabs-core/queue 的下载量有多少?

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

@haatlabs-core/queue 还在维护吗?

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