effect-mq README

The project's README from github.com/TeamWarp/effect-mq. As one markdown file: README.md.

effect-mq

Effect-native background jobs: schema-first job definitions, a storage-agnostic queue core, a worker runtime, and a Postgres store that lives inside your drizzle schema. Built on Effect v4; inspired by BullMQ's semantics and effect/workflow's DX.

→ Documentation: effect-mq.com — the package README (packages/effect-mq, also shown on npm) covers the same ground in one page.

Maintained by Warp. We're hiring.

import { Job } from "effect-mq"
import { Effect, Schema } from "effect"

class SendEmail extends Job.make("SendEmail", {
  payload: { to: Schema.String, subject: Schema.String },
  success: Schema.String,
  idempotencyKey: ({ to, subject }) => `${to}:${subject}`,
  metadata: ({ to }) => ({ to }),
  defaults: { attempts: 3, backoff: { type: "exponential", delay: "1 second" } }
}) {}

const producer = Effect.gen(function*() {
  const jobId = yield* SendEmail.enqueue({ to: "[email protected]", subject: "hi" })
})

Highlights

Repository layout

packages/effect-mq        the published package (src + tests, incl. the
                          Postgres and Redis suites under test/)
examples/tour             THE demo: four scenes against real Postgres +
                          Redis (kill -9 durability, dedup, a paused
                          cross-store flow) plus a live dashboard —
                          see examples/tour/README.md
examples/basic            minimal in-memory end-to-end: bun src/main.ts
docker-compose.yml        Postgres 17 (5433) + Redis 8 (6380) for the
                          storage test suites
tools/oxlint/anti-slop    local lint plugin enforcing honest types

Development

bun install
bun run check     # TypeScript 7, per package
bun run lint      # oxlint (incl. anti-slop rules)
bun run test      # vitest 4 + @effect/vitest, TestClock-driven
                  # (storage suites self-skip without their backing service)
bun run test:pg   # docker compose up + the Postgres suite
bun run test:redis  # docker compose up + the Redis suite
bun run ready     # check + lint + test
bun run build     # emit dist (tsc, .ts imports rewritten to .js)

The store conformance suite (effect-mq/testing) runs against the in-memory driver, real Postgres, and real Redis — under TestClock in all cases, because drivers take all time as parameters from the Effect Clock.

Release history lives in CHANGELOG.md; planned work in ROADMAP.md.

Releasing

CI (.github/workflows/ci.yml) runs check/lint/tests (with Postgres and Redis service containers) on every push and PR. Publishing to npm happens on version tags:

# bump "version" in packages/effect-mq/package.json, then
git tag v0.2.0 && git push --tags

The publish job runs npm publish with provenance; it needs an NPM_TOKEN repository secret. The package's prepack builds dist and swaps the dev (TS-source) exports for dist exports; postpack restores them. Verify a release candidate locally with:

cd packages/effect-mq && bun pm pack   # then inspect / install the tarball

License

MIT

effect-mq (TeamWarp/effect-mq)

Searching Database…

这是什么?effect-mq 是一个 Effect 原生的后台任务与消息队列库:以 schema 为先的任务定义、与存储无关的队列核心、工作器运行时,以及 Postgres(经 Drizzle)和 Redis 的存储实现。
这是我要导入的库,还是要单独运行的服务?它是一个 TypeScript 库,按可摇树优化的模块划分(核心、drizzle-postgres 存储、redis 存储、测试套件),由你接入自己的 Effect 应用;没有独立的服务器可执行文件。
怎么把它接进我的项目?安装 effect-mq 和你需要的存储模块,重新导出提供的 drizzle schema 工厂,让 drizzle-kit 管理任务表的迁移,然后定义任务并针对该存储运行工作器运行时。
使用它需要 Effect 和 Postgres 或 Redis 实例吗?需要。它构建在 Effect v4 之上,至少需要一个后端存储——Postgres(用 FOR UPDATE SKIP LOCKED 和 LISTEN/NOTIFY 认领任务)或 Redis(带发布/订阅的原子 Lua 脚本)——另外还有一个用于测试或一次性任务的内存驱动。
工作器崩溃或任务中途卡住会怎样?投递是至少一次语义,配有令牌保护的锁、心跳续期和卡死恢复;每次尝试都持久化到存储中的运行台账,而不是放在工作器内存里,所以重试能挺过崩溃。
可重复的定时任务如何避免在多个工作器间重复触发?每个触发时点都在一次原子的存储操作里完成认领和入队,无论多少个工作器在运行、无论保留设置如何,都保证每个时点恰好产生一个任务。
它提供哪些去重选项?它支持 pending-dedup(待处理去重)、throttle(节流)、debounce(防抖)和 replace-while-delayed(延迟期间替换),全部使用独立的去重键,因此实际的任务 id 永远不会被改写。
我可以把不同的任务发到不同的存储吗?可以。任务可以绑定到命名存储——比如业务关键任务用 Postgres,一次性任务用内存或 Redis——而且这种路由在编译期就被强制执行。
有内置的仪表盘界面吗?没有内置界面,但 effect-mq 暴露了一个仪表盘数据层:带元数据过滤的列表、键集分页、轮询、重试,以及按任务和按存储的保留策略,你可以在它之上搭建仪表盘。
What are similar projects?bull, rq, tork, carno.js, react-starter-kit, rankme.fast, dockhand, asynq
Creator
TeamWarp
Size
0.7 MB
Stars
188
Updated
CommitSep 09
Age
1mo
Commits · 90 Days