fix(adopt): 后台预升级加闲置门控并修采纳徽标定位与取消确认
This commit is contained in:
@@ -459,6 +459,7 @@ def api_adopt_list(sid=0):
|
||||
c.close()
|
||||
|
||||
_UPGRADE_LOCK = threading.Lock() # 决策 341:采纳内升级与后台预升级互斥——同批次绝不并发重导
|
||||
ACTIVITY = {"ts": 0.0} # 决策 341 补记:最近交互请求时刻(api_server 每请求刷新)——后台预升级的闲置门控用
|
||||
|
||||
|
||||
def _upgrade_batch_row(hc, row):
|
||||
@@ -623,15 +624,42 @@ def upgrade_stale_batches_once():
|
||||
|
||||
|
||||
def upgrade_stale_batches_bg():
|
||||
"""决策 341:启动后台线程跑 upgrade_stale_batches_once()——先让服务就绪(3s)再动库。"""
|
||||
"""决策 341 补记二(2026-11-15 主人实录「采纳中一直这样+进工作台很慢」):后台预升级加
|
||||
**闲置门控**——最近 60 秒内有任何交互请求就让路(绝不跟主人抢库),停手 60 秒后才默默升一批;
|
||||
升级失败的批次登记跳过(防死循环)。全部升完线程自然结束。"""
|
||||
def _bg():
|
||||
time.sleep(3)
|
||||
try:
|
||||
up, skip, total = upgrade_stale_batches_once()
|
||||
if total:
|
||||
print("279 后台预升级完成:升级 %d / 跳过 %d / 共 %d 批" % (up, skip, total), flush=True)
|
||||
except Exception as _e:
|
||||
print("279 预升级线程异常(不挡服务):%s" % _e, flush=True)
|
||||
skipped = set()
|
||||
while True:
|
||||
while time.time() - ACTIVITY["ts"] < 60:
|
||||
time.sleep(5)
|
||||
hc = conn()
|
||||
try:
|
||||
ph = ",".join("?" * len(skipped))
|
||||
row = hc.execute(
|
||||
"""SELECT * FROM batches WHERE kind='project'
|
||||
AND COALESCE(x_parser_ver,'')<>? %s ORDER BY id LIMIT 1"""
|
||||
% ("AND id NOT IN (%s)" % ph if skipped else ""), (job.PARSER_VER,)).fetchone()
|
||||
finally:
|
||||
hc.close()
|
||||
if row is None:
|
||||
if skipped:
|
||||
print("279 预升级完成:%d 批失败跳过,其余已全部升到 %s" % (len(skipped), job.PARSER_VER), flush=True)
|
||||
return
|
||||
try:
|
||||
hc2 = conn()
|
||||
try:
|
||||
r = _upgrade_batch_row(hc2, row)
|
||||
finally:
|
||||
hc2.close()
|
||||
print("279 预升级:批次 #%s「%s」%s"
|
||||
% (row["id"], (row["Name"] or "")[:20],
|
||||
"已升级" if r else "跳过(源件缺失/哈希不符/不可解析)"), flush=True)
|
||||
if not r:
|
||||
skipped.add(row["id"]) # 跳过的批次不再重选
|
||||
except Exception as _e:
|
||||
print("279 预升级批次 #%s 失败:%s" % (row["id"], _e), flush=True)
|
||||
skipped.add(row["id"])
|
||||
threading.Thread(target=_bg, name="upgrade-stale-batches", daemon=True).start()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user