feat(通知): 账号状态汇总(检测账号跑完 + 每日 09:30)
- 新事件 account.status.summary:总数/正常/异常/状态分布/异常账号清单 - 计划收尾检测 read_text(account_status) 才发,普通发布计划不刷屏 - 每日 09:30 全量汇总;ACCOUNT_STATUS_DAILY/ACCOUNT_STATUS_SUMMARY_AT 可配 - 生产企微 webhook 已订阅该事件;测试与文档同步
This commit is contained in:
@@ -442,6 +442,21 @@ def inline_task_steps(steps):
|
||||
return out
|
||||
|
||||
|
||||
def _has_account_status_read(steps):
|
||||
"""这组步骤里有没有「读取文字」写 `account_status`(决定跑完要不要发状态汇总)。"""
|
||||
for st in steps or []:
|
||||
if not isinstance(st, dict):
|
||||
continue
|
||||
p = st.get("params") or {}
|
||||
if (st.get("type") == "read_text"
|
||||
and (p.get("var") or "").strip() == "account_status"):
|
||||
return True
|
||||
for k in ("children", "then", "else"):
|
||||
if _has_account_status_read(p.get(k)):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def _app_id_for_steps(steps):
|
||||
"""从任务步骤里的 `open_app`/`stop_app` 的包名反查 App 注册表(任务段没有 app_id)。"""
|
||||
from core.models import AeApp
|
||||
@@ -760,6 +775,10 @@ def _make_tracker(plan, prepared, plan_run_id, date, app_d, act_d):
|
||||
job = prepared[0][0] if prepared else None
|
||||
devices = [dev for _, dev in prepared]
|
||||
total = len(devices)
|
||||
# 这次运行会不会写「账号状态」:有 read_text(account_status) 才在收尾发汇总,
|
||||
# 普通发布计划不刷这个通知。
|
||||
status_watch = any(_has_account_status_read((j.params or {}).get("steps"))
|
||||
for j, _ in prepared)
|
||||
|
||||
_segs = plan.get("segments") or []
|
||||
# 老计划(没有 segments)默认按发布流程统计;编排里所有段都不发布素材时,
|
||||
@@ -807,6 +826,9 @@ def _make_tracker(plan, prepared, plan_run_id, date, app_d, act_d):
|
||||
for a in dev["accounts"]:
|
||||
mapping[a] = st
|
||||
_finish_plan_run(plan_run_id, per_account=mapping)
|
||||
if status_watch:
|
||||
af.notify_account_status_summary(
|
||||
job_name=plan.get("name") or "", source="计划运行")
|
||||
except Exception as e:
|
||||
_log.warning("计划批次收尾失败(%s):%s", plan_run_id, e)
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user