多进程协调(W2-b)第一步:新增 app/cluster——工作进程在库里登记、心跳续租约(属主随进程,进程没了它认领的行一起到期),调度当班的租约,发给属主进程的停止 / 记事件请求,PostgreSQL 的 LISTEN/NOTIFY 叫醒,跨进程的互斥锁(咨询锁),SQLite 单进程守卫(第二个进程拒绝启动);运行、问数据一轮、起草 / 剖析 / 探查 / 评测 / 影子起草、文档、发布单记 owner,启动整理改成只接手属主不在了的行,当班进程隔一会儿再接手一次;运行的并发名额改成库里按交互 / 应用 / 定时 / 系统四类发(各有全站上限和优先级,设置里可调),替掉进程内的信号量;同源队记在库里;运行停止、记事件跨进程交给属主;运行事件、问数据事件跨进程转发(库里按 seq 追,不落库的流式增量和保活心跳只转给在看的进程);每日花费账先占住那一行再读写;访问密钥限流、登录失败计数在 PostgreSQL 时记在库里;登录设置、对外地址、向量模型、能力快照、数据源连接池、应用页面缓存跨进程失效;上传版本库、记录表、按需探查、出具、召回、补算、按需视图、个人刷新、定时发起的锁换成跨进程的锁

This commit is contained in:
ThearchyHelios
2026-10-19 11:40:33 +08:00
parent 9a0d87aa6e
commit 87f0d62f9b
74 changed files with 3521 additions and 447 deletions
+3 -2
View File
@@ -243,7 +243,8 @@ async def test_background_jobs_follow_the_lane_order(client, shop):
await session.commit()
ids = {"introspect": intro.id, "draft": draft.id, "profile": profile.id}
# 队里是 起草(在做)→ 剖析(排着);探查刚建、还没进队:排在队里的后面
tickets = [runtime.lanes.enter(sid, "draft", ids["draft"]), runtime.lanes.enter(sid, "profile", ids["profile"])]
tickets = [await runtime.lanes.enter(sid, "draft", ids["draft"]),
await runtime.lanes.enter(sid, "profile", ids["profile"])]
try:
items = (await client.get(f"/api/datasources/{sid}/background-jobs")).json()["items"]
assert [i["kind"] for i in items] == ["draft", "profile", "introspect"], items
@@ -253,7 +254,7 @@ async def test_background_jobs_follow_the_lane_order(client, shop):
assert {"total", "done", "status"} <= set(items[0])
finally:
for t in tickets:
t.release()
await t.release()
async with SessionLocal() as session:
for model, key in ((IntrospectJob, "introspect"), (CatalogDraftJob, "draft"), (CatalogProfileJob, "profile")):
await session.execute(delete(model).where(model.id == ids[key]))