fix(sources): 快照开始前收尾本站遗留的运行中记录;v0.3.39
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
This commit is contained in:
1 parent
5c74666148
commit
8ff1817845
14 files changed
+51
-11
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@umt/server",
|
||||
"version": "0.3.38",
|
||||
"version": "0.3.39",
|
||||
"exports": { ".": "./src/main.ts" },
|
||||
"tasks": {
|
||||
"dev": "deno run -A --watch --env-file=../../.env src/main.ts",
|
||||
|
||||
@@ -216,6 +216,18 @@ export async function snapshotSite(
|
||||
if (input.kind === "periodic" || input.kind === "manual") {
|
||||
maxPages = Math.min(maxPages, (await rt.siteAccess(site.key)).snapshotMaxPages);
|
||||
}
|
||||
// 进程被杀或旧版本卡死留下的「运行中」记录:超过两倍截止时间就按中断收尾(清理任务不删运行中的行)
|
||||
await db
|
||||
.updateTable("site_snapshot")
|
||||
.set({
|
||||
status: "failed",
|
||||
error: jsonb({ kind: "internal", message: "上次快照中断,没有收尾" }),
|
||||
finished_at: rt.now(),
|
||||
})
|
||||
.where("site_id", "=", site.id)
|
||||
.where("status", "=", "running")
|
||||
.where("started_at", "<", new Date(rt.now().getTime() - 2 * (opts.deadlineMs ?? SNAPSHOT_DEADLINE_MS)))
|
||||
.execute();
|
||||
const snap = await db
|
||||
.insertInto("site_snapshot")
|
||||
.values({
|
||||
|
||||
@@ -59,4 +59,27 @@ describe.skipIf(!up)("快照截止时间", () => {
|
||||
expect(snap.status).toBe("failed");
|
||||
expect(snap.finished_at).not.toBeNull();
|
||||
});
|
||||
|
||||
it("旧的「运行中」记录在下一次快照开始时按中断收尾,刚开始的不动", async () => {
|
||||
const mk = (ago: number) =>
|
||||
h.db
|
||||
.insertInto("site_snapshot")
|
||||
.values({
|
||||
site_id: siteId,
|
||||
kind: "periodic",
|
||||
filters: "{}",
|
||||
definition_version: "t",
|
||||
started_at: new Date(Date.now() - ago),
|
||||
})
|
||||
.returning("id")
|
||||
.executeTakeFirstOrThrow();
|
||||
const stale = await mk(3_600_000);
|
||||
const fresh = await mk(100);
|
||||
await snapshotSite(h.rt, { siteId, kind: "periodic" }, { deadlineMs: 300 });
|
||||
const get = (id: string) =>
|
||||
h.db.selectFrom("site_snapshot").selectAll().where("id", "=", id).executeTakeFirstOrThrow();
|
||||
expect(await get(stale.id)).toMatchObject({ status: "failed" });
|
||||
expect((await get(stale.id)).error).toMatchObject({ message: "上次快照中断,没有收尾" });
|
||||
expect((await get(fresh.id)).status).toBe("running");
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@umt/web",
|
||||
"version": "0.3.38",
|
||||
"version": "0.3.39",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
Reference in new issue
Block a user