Skip to content

hop→waker 迁移 · 实现(SDK 接入 + 任务注册 + 双模式部署 + 可观测) - #162

Merged
todosdev[bot] merged 1 commit into
mainfrom
tds/conv-01a18153-6df9-7b58-ab90-017ca43eacb8
Oct 28, 2026
Merged

todosdev[bot] merged 1 commit into
mainfrom
tds/conv-01a18153-6df9-7b58-ab90-017ca43eacb8

Conversation

@todosdev

@todosdev todosdev Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • 接入 @workerhub/waker-client 官方 SDK(源码形态引入),支持将每日清理任务(0 3 * * *)调度平滑接入 waker 平台回调,保留原生 CF Cron Trigger 默认模式,自部署零额外依赖。
  • 业务逻辑收敛至单点 runCleanup(env),原生 scheduled() 与 POST /_waker/execute 共享同一份删除判据与事务语义;新增 D1 加法迁移 schema_v3(waker_executions)用于 executionId 幂等认领。
  • 部署流水线支持 WAKER_MODE=cron|waker 与 WAKER_TRIGGERS=keep|remove 双模式改写、secrets 文件按需注入 WAKER_SIGNING_KEY 以及发布期 Cloudflare API cron schedules 与密钥绑定双重闸门校验。

Changes

  • waker SDK 接入与路由:
    • apps/worker/src/waker/:逐字拷贝 waker 官方 SDK 2.0.0 源文件(commit 2b1eb68)与 README;
    • apps/worker/src/routes/waker.ts:挂载 /_waker 回调路由;非 waker 模式显式响应 JSON 404(waker_disabled),防止落入 SPA 兜底 200;
    • apps/worker/src/services/cleanup.ts:抽离统一清理函数(verifications 与 totp_used 批量删除);
    • apps/worker/src/services/waker.ts:组装带 D1 账本与签名验签的 receiver,产出结构化可观测日志;
    • apps/worker/src/index.ts:注册 /_waker 路由并使 scheduled() 委托统一清理函数。
  • 数据库加法迁移:
    • apps/worker/src/lib/migrations.ts & apps/worker/migrations/0003_waker_executions.sql:新增 schema_v3 幂等账本表,列定义与 SDK executionLedgerDdl() 严格一致。
  • 部署流水线与构建改写:
    • .github/scripts/configure-waker-mode.mjs:部署期按变量重写 wrangler.toml;
    • .github/workflows/deploy.yml:增加模式配置步、secrets 文件条件注入与 verify 参数传递;
    • .github/scripts/verify-deployment.sh:断言发布版本上的 WAKER_SIGNING_KEY 绑定及 Cloudflare schedules。
  • 文档与测试:
    • README.md & README.zh-CN.md:增加双模式部署、参数规范、切换与回滚说明;
    • 增加 waker-callback.test.ts、waker-schema.test.ts、test-waker-mode.mjs 等完备测试用例。

Testing

  • pnpm check(Biome 代码检查与格式化 119 files 全部通过)
  • pnpm typecheck(TypeScript 类型检查全部通过)
  • pnpm test(Worker 129 tests、Web 55 tests + 4 Vitest DOM 全部通过)
  • node --test .github/scripts/test-deploy-checks.mjs .github/scripts/test-waker-mode.mjs(62 tests 全部通过)
  • node --test .github/scripts/test-d1-migrations.mjs(18 tests 全部通过)
  • shellcheck .github/scripts/*.sh(通过)
  • wrangler deploy --dry-run(验证 cron 与 waker 模式产物及绑定符合预期)

- Run the nightly cleanup from both the native Cron Trigger and a signed
  waker callback; dedupe executionId in {prefix}waker_executions (schema_v3).
- Rewrite wrangler config per WAKER_MODE/WAKER_TRIGGERS, inject the signing
  key only in waker mode, and gate deploys on secret bindings and schedules.
- Document both deployment modes, switch order and rollback in README (en/zh).

Checkpoint: Ex4plfNZMsFjYlhm3htQZ
@todosdev
todosdev Bot merged commit dfcbd3e into main Oct 28, 2026
4 checks passed
@mapxn
mapxn deleted the tds/conv-01a18153-6df9-7b58-ab90-017ca43eacb8 branch November 8, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants