mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-26 06:42:33 +00:00
表的「上次剖析」取真正开始过的那一次:没开始就停了的、还排着的不再挡掉上一次真正剖析,保留也不清它
复核 R2。以前每张表的「最近一次剖析」只按任务的建立先后取,没开始就结束了的那一项(停在前面的表上、任务止损或整体 出错后没轮到)、排队中还没轮到的那一项也算。于是表详情、表清单的上次剖析变成一条没有行数、没有发过的查询的「已停止」; prune 只保护排第一的那一项,上一次真正剖析所在的任务就会被清掉——行数估算、日期范围、发过的查询只存在剖析任务里 (设计文档 §5 否决了写进目录),删了就找不回来,和 §4.8「表详情的上次剖析永远有」相抵。建一个排队任务时顺手的 prune 就能清掉它。 - _ranked(替代 _latest_per_table)一个子查询给两个排名:shown 是真正开始过(started_at 有值;收过尾的表都有)的最近 一项,一次都没开始过才退回最近一项;latest 是最近一项,只用来看这张表是不是已经排在进行中的任务里。 - last_profiles、last_detail、prune 的保护都按 shown。表还排在进行中的任务里时,表详情给的是上一次真正剖析的明细, 排队、在做由页面跟着的任务说(前端 profileCell / ProfileSection 的 live 本来就这样)。 - due_reason 也按 shown(加上 queued:已经排在进行中的任务里不算要剖析),不照复核建议看最新一项:不然表清单一边显示 「上次剖析:完成」,一边说「上次剖析没做完」。真正没剖析完整的表照样 due——上次真正剖析是 partial 的仍是 unfinished, 从没开始过的退回最近一项(cancelled)仍是 unfinished,剖析之后冒出的待核实关系仍是 new_relations。 测试:新增先剖析 channels、再在 [visits, channels] 停在 visits 上——channels 的上次剖析仍是第一次(行数、发过的查询 都在),不算要剖析;prune(keep=1) 不删;保留数为 0 时再建一个排队任务也不删。
This commit is contained in:
@@ -670,6 +670,41 @@ async def test_the_table_detail_and_list_carry_the_last_profile(client, make_sou
|
||||
assert (await _notes(client, sid, "gates"))["last_profile"] is None
|
||||
|
||||
|
||||
async def test_the_last_profile_is_the_last_one_that_actually_ran(client, make_source, scenic_db, monkeypatch):
|
||||
"""channels 剖析完(ok);再建 [visits, channels]、停在 visits 上:channels 没开始就停了。表详情、表清单的「上次剖析」
|
||||
仍是上一次真正剖析的那一项(行数、发过的查询都在),不算没做完;保留不删它所在的任务,之后再建一个排队的任务也不删。"""
|
||||
sid = await make_source(scenic_db, options=_on(), draft=["visits", "channels"])
|
||||
first = await _profile(client, sid, ["channels"])
|
||||
gate = _hold_queries(monkeypatch, _at_visits_codes)
|
||||
second = (await _start(client, sid, ["visits", "channels"])).json()["job"]
|
||||
await asyncio.wait_for(gate.entered.wait(), 10)
|
||||
stopped = (await client.post(f"{_url(sid)}/{second['id']}/cancel")).json()["job"]
|
||||
assert [(t["table_name"], t["status"]) for t in stopped["tasks"]] == [("visits", "partial"),
|
||||
("channels", "cancelled")]
|
||||
|
||||
last = (await _notes(client, sid, "channels"))["last_profile"]
|
||||
assert (last["job_id"], last["status"]) == (first["id"], "ok")
|
||||
assert last["started_at"] and last["queries"] and last["row_estimate"] and last["query_log"]
|
||||
rows = await _rows(client, sid)
|
||||
assert rows["channels"]["last_profile"]["job_id"] == first["id"] and not rows["channels"]["profile_due"]
|
||||
assert rows["visits"]["last_profile"]["job_id"] == second["id"], "visits 真正剖析过:上次剖析是停下的这一次"
|
||||
async with SessionLocal() as session:
|
||||
assert await catalog_profile_jobs.prune(session, sid, keep=1) == 0, "first 是 channels 上次剖析所在的任务"
|
||||
|
||||
# 结束了的任务超出保留数时再建一个排队的任务(建任务时顺手清):排着的那一项不算 channels 的上次剖析
|
||||
monkeypatch.setattr(catalog_profile_jobs, "KEEP_JOBS", 0)
|
||||
monkeypatch.setattr(catalog_profile_jobs.manager, "start", lambda job_id: None)
|
||||
queued = (await _start(client, sid, ["channels"])).json()["job"]
|
||||
async with SessionLocal() as session:
|
||||
left = set((await session.execute(select(CatalogProfileJob.id)
|
||||
.where(CatalogProfileJob.source_id == sid))).scalars())
|
||||
assert {first["id"], second["id"], queued["id"]} == left
|
||||
assert (await _notes(client, sid, "channels"))["last_profile"]["job_id"] == first["id"]
|
||||
row = (await _rows(client, sid))["channels"]
|
||||
assert row["last_profile"]["job_id"] == first["id"] and not row["profile_due"], "已经排进任务里了"
|
||||
await client.post(f"{_url(sid)}/{queued['id']}/cancel")
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# 设置迁移、保留
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user