feat: 批量重评分片并发(老爸:这么多key不能并发?)

- batch_reassess --shard K/N: index%N==K分片,N进程互不重叠
- llm_client LLM_KEY_OFFSET: key池起始位错开,避免N进程压同一首选key
- SKIP_FLUSH=1时worker不发摘要,parallel_batch.sh收尾统一flush
- parallel_batch.sh: N路并行+等待+统一digest
This commit is contained in:
hmo
2026-07-24 09:02:34 +08:00
parent 9fad0cfa14
commit a559fc84dd
3 changed files with 48 additions and 10 deletions
+19 -7
View File
@@ -633,8 +633,18 @@ def main():
"SELECT code FROM holding_strategies WHERE status='active' ORDER BY decision_type, code").fetchall()
conn.close()
codes = [r[0] for r in rows]
print(f"待处理: {len(codes)}只 (type={dtype or 'all'}, force_today={force_today})")
# ── 分片并发(2026-07-24 老爸:这么多key不能并发?)──
# --shard K/N:本 worker 只处理 index%N==K 的股票,N 个进程并发互不重叠。
_shard_k, _shard_n = 0, 1
if "--shard" in sys.argv:
_sk = sys.argv[sys.argv.index("--shard") + 1] # 格式 K/N
_shard_k, _shard_n = int(_sk.split("/")[0]), int(_sk.split("/")[1])
if _shard_n > 1:
codes = [c for i, c in enumerate(codes) if i % _shard_n == _shard_k]
print(f"待处理: {len(codes)}只 (type={dtype or 'all'}, force_today={force_today}"
+ (f", shard={_shard_k}/{_shard_n}" if _shard_n > 1 else "") + ")")
ok = 0
fail = 0
@@ -679,11 +689,13 @@ def main():
print(f"完成: {ok}成功, {fail}失败, {skip}跳过")
print(f"{'='*50}")
# ── 推荐摘要:本轮新增推荐聚成一条推送(防逐只轰炸)──
try:
from mofin_db import flush_rec_digest
flush_rec_digest()
except Exception as _e:
print(f" ⚠️ 推荐摘要发送失败: {_e}")
# 并发分片模式(SKIP_FLUSH=1)下由 launcher 统一 flush,避免先到者发半成品摘要
if not os.environ.get("SKIP_FLUSH"):
try:
from mofin_db import flush_rec_digest
flush_rec_digest()
except Exception as _e:
print(f" ⚠️ 推荐摘要发送失败: {_e}")
if __name__ == "__main__":
main()