@adonis-agora/durable

中文文档
0.59.0发布于 2026/11/05MITTypeScriptES Module构建来源已验证近 30 天下载 1.4万

Durable cross-app workflows for AdonisJS — deterministic replay engine, AdonisJS binding, ace commands, dashboard, OpenTelemetry, Telescope, testing harness and Redis admission, all in one package. Part of the Agora ecosystem.

原始使用文档
文档目录3 节
  1. Transports
  2. Workflows codegen (Assembler hook)
  3. License

@adonis-agora/durable

npm version npm downloads CI license

Durable, resumable workflows for AdonisJS: write a workflow as plain async code; every step is checkpointed, so a run survives crashes and deploys and resumes from its last completed step. Steps can run in-process or on remote workers (another Adonis process, a NestJS worker, or a Python worker), and it stays one run with one timeline.

node ace add @adonis-agora/durable

Define a workflow under app/workflows/ (auto-registered at boot):

// app/workflows/order_workflow.ts
import { BaseWorkflow, type WorkflowCtx } from '@adonis-agora/durable'

export default class OrderWorkflow extends BaseWorkflow {
  static workflow = { name: 'order', version: '1' }

  async run(ctx: WorkflowCtx, order: { id: number; total: number }) {
    const charge = await ctx.localStep('charge', async () => chargeCard(order))
    await ctx.localStep('ship', async () => ship(charge))
    return { status: 'shipped' }
  }
}

Start it from a controller, and use the engine service for everything else:

import OrderWorkflow from '#workflows/order_workflow'
import engine from '@adonis-agora/durable/services/main'

const { runId } = await OrderWorkflow.dispatch({ id: 1, total: 4200 }, { runId: 'order:1' })
const result = await engine.waitForRun(runId)

Defaults to the in-memory store + the test-only memory transport (single process, zero infra). Supply a persistent store and a cross-process transport in config/durable.ts for production. When @adonis-agora/context is installed, the originating tenant/user/correlation carrier rides each dispatched task (best-effort, no hard dependency).

Full docs: https://davidecarvalho.github.io/agora/docs/durable

Transports

Select a transport by name in config/durable.ts:

  • transports.eventEmitter() — production in-process transport over a Node EventEmitter. Zero external infrastructure (no DB, no Redis, no broker): step handlers run in this same process, decoupled from the dispatching workflow over the event loop. Use it for a single-process production app.
  • transports.queue({ connection }) — cross-process over @adonisjs/queue.
  • transports.db({ connection }) — cross-process over the app database (@adonisjs/lucid), no broker.
  • transports.bullmq({ connection }) — cross-process over BullMQ on Redis, wire-compatible with the NestJS (nestjs-durable) BullMQ transport and the Python worker. Pair it with controlPlanes.redis(...).
  • transports.memory() — test-only (drives dispatch straight into the handler).
import { defineConfig, transports } from '@adonis-agora/durable'

export default defineConfig({
  transport: 'event-emitter',
  transports: {
    'event-emitter': transports.eventEmitter(),
  },
})

Workflows codegen (Assembler hook)

node ace configure registers two AdonisJS Assembler init hooks that generate typed barrels of app/workflows/ and app/steps/ at build/dev time — exactly how core generates the controllers/events/listeners barrels. The provider imports the generated barrels at boot and registers every BaseWorkflow class and step, instead of scanning the directories with readdir at runtime. The file watcher regenerates a barrel whenever a workflow or step file changes. The barrels import through the #workflows/* and #steps/* subpath imports, which configure adds to your package.json.

Register it in adonisrc.ts (the configure command does this for you):

export default defineConfig({
  hooks: {
    init: [
      () => import('@adonis-agora/durable/hooks/workflows'),
      () => import('@adonis-agora/durable/hooks/steps'),
    ],
  },
})

If the hook is not registered (or the barrel hasn't been generated yet) the provider falls back to the runtime directory scan, so apps that don't opt in keep working unchanged. Opt out of discovery entirely with workflowsPath: false (or stepsPath: false).

A modular app can list several directories: workflowsPath / stepsPath take an array, and so does the hooks' source option. Names must be unique across those directories, and a clash fails boot naming both files.

License

MIT © Davi Carvalho

版本与发布记录

@adonis-agora/durable 共发布 112 个版本,首次发布于 2026/06/23;过去 12 个月发布了 112 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.59.0latest2026/11/051 天前
0.58.32026/11/023 天前
0.58.22026/10/315 天前
0.58.12026/10/306 天前
0.58.02026/10/307 天前
0.57.12026/10/297 天前

关于 @adonis-agora/durable 的常见问题

@adonis-agora/durable 是什么?

Durable cross-app workflows for AdonisJS — deterministic replay engine, AdonisJS binding, ace commands, dashboard, OpenTelemetry, Telescope, testing harness and Redis admission, all in one package. Part of the Agora ecosystem.

如何安装 @adonis-agora/durable?

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

@adonis-agora/durable 支持 TypeScript 吗?

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

@adonis-agora/durable 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@adonis-agora/durable 需要什么版本的 Node.js?

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

@adonis-agora/durable 可以商用吗?

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

@adonis-agora/durable 的下载量有多少?

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

@adonis-agora/durable 还在维护吗?

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