Files
dsh_ai1net_server/归档/接续历史/机制排查/S12_一次性排期停用_20261002.py
T
admin c1b5e4d966 chore(工作区): 全量入库 + 补齐 .gitignore(以工作区为准)
- 变更规模:新增 514 / 修改 62 / 重命名 155 / 删除 4(归档重组与文档轮次)
- .gitignore 修:`归档/**/db-cwd归一-备份-*/` —— 原规则写绝对层级(归档/db-cwd归一-…),
  目录搬进 归档/配置与备份/ 后**静默失效**,43 MB 的 DB 备份又变成未跟踪
- .gitignore 补:嵌套 git 内部数据(归档/内嵌git-20261008/、归档/skills-git-旧线-20261007/dotgit-原样移出/)
- .gitignore 补:运行态与部署副本(.workbuddy/collab/、.workbuddy/tools/、.workbuddy/.load-pending、.workbuddy/tmp-*)
- .gitignore 补:备份件(*.bak-*)
- 未跟踪文件从 2190 降到 890(其余为 归档/ 归档件与 .workbuddy/memory/ 知识文件,按口径入库)
2026-10-10 23:13:22 +08:00

55 lines
2.4 KiB
Python

import sqlite3, sys, json, datetime
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
DB = r"E:/ProgramData/.workbuddy/workbuddy.db"
TARGET = ("deleted_at IS NULL AND status='ACTIVE' AND schedule_type='once' "
"AND next_run_at IS NULL")
SELF = "45d4e2d4-a73d-4cdf-ac78-1047326f0f8d"
c = sqlite3.connect(DB, timeout=20)
c.execute("PRAGMA busy_timeout=10000")
before = c.execute(f"select count(*) from automations where {TARGET}").fetchone()[0]
print("BEFORE =", before)
rows = c.execute(
f"select id, name from automations where {TARGET} order by name").fetchall()
print("TARGET_ROWS =", len(rows))
assert before == len(rows), "盘点与列表不一致,停手"
# 只逐条 UPDATE(不批量),每条改完立刻回读核对
now_ms = int(datetime.datetime.now().timestamp() * 1000)
results = []
for aid, name in rows:
assert aid != SELF, "拒改:本会话自己的排期"
cur = c.execute(
f"update automations set status='PAUSED', updated_at=? where id=? and {TARGET}",
(now_ms, aid))
# 立刻回读核对(不把「返回成功」当「已生效」)
chk = c.execute("select status, schedule_type, next_run_at, deleted_at "
"from automations where id=?", (aid,)).fetchone()
ok = (cur.rowcount == 1 and chk[0] == 'PAUSED' and chk[1] == 'once'
and chk[2] is None and chk[3] is None)
results.append((aid, name, cur.rowcount, chk, ok))
print(f" [{'OK ' if ok else 'FAIL'}] {name} rowcount={cur.rowcount} now={chk}")
c.commit()
after = c.execute(f"select count(*) from automations where {TARGET}").fetchone()[0]
print("AFTER =", after)
# 回归:周期排期一个没少、待跑的一次性排期没被动
print("RECURRING_ACTIVE_AFTER =", c.execute(
"select count(*) from automations where deleted_at is null and status='ACTIVE' "
"and schedule_type='recurring'").fetchone()[0], "(before=3)")
print("ONCE_PENDING_STILL_ACTIVE =", c.execute(
"select count(*) from automations where deleted_at is null and status='ACTIVE' "
"and schedule_type='once' and next_run_at is not null").fetchone()[0], "(before=2)")
print("TOTAL_ROWS_AFTER =", c.execute("select count(*) from automations").fetchone()[0],
"(before=141 ⛔不删行)")
print("INTEGRITY_AFTER =", c.execute("PRAGMA integrity_check").fetchone()[0])
c.close()
ok_all = after == 0 and all(r[4] for r in results)
print("VERDICT =", "PASS" if ok_all else "FAIL")