Repository navigation
eNotify waker 迁移 · 实现(receiver + 极简接入) - #160
Merged
todosdev[bot] merged 2 commits intoOct 28, 2026
Merged
Conversation
added 2 commits
October 28, 2026 20:00
Copy waker-client 2.0.0 verbatim into worker/src/waker, mount /_waker before the SPA fallback, and route both the native cron and the callback through runSchedulerTick with an atomic D1 hour claim. Adds schema_v3 (execution ledger + claim table), optional WAKER_SIGNING_KEY injection with a CI interlock, docs and 45 tests. Checkpoint: nLhckbvBTlUe_VBsQbdaN
Manual triggers and dead-letter replays arrive with the dispatch time and now run the sweep without taking the hourly slot, so the console's "run now" is no longer swallowed by cron's claim. A waker retry may also take over its own orphaned hour claim after 20s (cron claims never), and the receiver host now answers escaping errors with JSON. Checkpoint: BZSykkb9FngNpc7Yx2FUi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/_waker,与原生 cron 共用唯一入口runSchedulerTick,按 UTC 整点做 D1 原子认领,双跑期间也不会重复推送。WAKER_SIGNING_KEY(可选、只经 secrets-file 注入);不配就走原生 cron,receiver 仍挂载但 fail closed,未配 key 的部署必然成功。schema_v3(SDK executionId 幂等账本 + 整点认领表);提醒业务规则、渠道、模板、窗口、历法、auto_renew全部零改动。Changes
worker/src/services/scheduler-tick.ts:两入口共用runSchedulerTick(认领 →await handleScheduled→ 清 7 天前认领);失败语义 cron 保留认领、waker 释放并抛错;wakerSigningKey()是唯一闸门。手动触发/死信重放不占整点槽位;waker 超时/崩溃后 20s 可接管自己的占位(cron 认领永不接管)。worker/src/db/queries/scheduler-ticks.ts:INSERT … ON CONFLICT(tick_key) DO NOTHING+meta.changes;释放/清理/CAS 接管/表名 helper,前缀只经getTablePrefix(TABLE_PREFIX三态)。worker/src/services/waker-callback.ts+worker/src/routes/waker.ts:jobhourly-reminder-sweep、D1 账本、onJobError只记标识与 message;临时宿主补onError,异常回 JSON 500 而非裸文本。worker/src/index.ts:/_waker注册在 SPA 兜底之前;scheduled()改为await runSchedulerTick(…, source:"cron")(不再waitUntil)。worker/src/waker/:@workerhub/waker-client2.0.0(waker2b1eb68)7 个文件逐字拷贝 + README;只调用 receiver / D1 账本 / 路径常量,mountWakerReceiver、createWakerClient*、syncManifest、resolveWakerMode均未调用;biome.json排除该目录。worker/src/lib/migrations.ts末尾追加schema_v3({prefix}waker_executions8 列 +{prefix}scheduler_tick_claims+idx_…_claimed_at,只增、字面量无;);worker/src/db/schema.sql同步两张表。.github/workflows/deploy.yml:可选注入WAKER_SIGNING_KEY(空/占位跳过,只打configured/not configured,永不打印值)+ 互锁(无[triggers]且 key 为空 ⇒ 部署失败);worker/wrangler.toml未改动,[triggers]继续保留(切换属后续独立单)。worker/package.json/pnpm-lock.yaml:hono→^4.13.14(对齐 SDK peer)。README.md/README.en.md/CLAUDE.md:唯一配置项与三种部署态、控制台建任务全策略、迁移、双跑/切换/停用/轮换、手动触发与超时重试的边界说明。scheduler-tick/waker-callback/scheduled-entry/waker-equivalence四个测试文件;既有迁移名断言补齐schema_v3;test/support/sqlite-d1.ts补meta.changes。Testing
pnpm lint:0 error(1 warning / 1 info,与迁移前基线一致);pnpm format:check:0 error;pnpm typecheck、pnpm build:通过。pnpm test:23 files / 301 tests 全绿(基线 247 + 新增 54)。signing_key_missing、缺头 400、GET 404(非 200 HTML)且 DB/业务零调用;篡改签名与过期时间戳 401;同一 executionId 重放不重跑、不重推;两入口并发只跑 1 次,同小时 cron 先跑后 waker 回duplicate_tick;同一 fixture 下 waker 与 cron 的推送体、历史行(含trigger_source)逐项相等;cron 已认领整点时手动触发仍真实运行;超时后重试能接管账本与认领补完该小时。worker/src/waker/7 文件shasum与上游client/src一致;deploy 注入/互锁脚本本地跑通 6 种组合且输出不含密钥值;wrangler deploy --dry-run打包通过;仓库内无WAKER_MODE/WAKER_URL/WAKER_TRIGGERS或项目令牌配置。schema_v3迁移执行、waker 控制台建任务后的手动触发与端到端延迟实测(验收 2 / 7)。