54 lines
2.4 KiB
Python
54 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")
|