feat(shipping-notice): 增加 RPA Worker 心跳上报与状态查询功能
This commit is contained in:
1 parent
c3f05ba96b
commit
5a147c4d85
49 files changed
+4032
-1500
No files matched your search
@@ -76,11 +76,30 @@ _WECOM_STATUS_LABEL = {
|
||||
_WECOM_EVENT_TYPE = 'schedule_completed'
|
||||
|
||||
|
||||
def _build_schedule_run_wecom_jump_params(task: ScheduleTask, run: ScheduleRun) -> dict[str, Any]:
|
||||
"""
|
||||
构造排程企微 textcard 跳转 query 参数。
|
||||
|
||||
核心逻辑:指向管理端 /admin/schedules;有原始库存归档时附加 raw_zip=1 供深链展示下载入口。
|
||||
"""
|
||||
from app.services.schedule.shipping_inventory_rpa_archive import inventory_raw_zip_available_from_summary
|
||||
|
||||
summary = run.response_summary_json if isinstance(run.response_summary_json, dict) else {}
|
||||
params: dict[str, Any] = {
|
||||
'task_id': task.id,
|
||||
'run_id': run.id,
|
||||
}
|
||||
if inventory_raw_zip_available_from_summary(summary):
|
||||
params['raw_zip'] = '1'
|
||||
return params
|
||||
|
||||
|
||||
def _build_schedule_run_wecom_description(run: ScheduleRun) -> str:
|
||||
"""
|
||||
组装排程完成企微 textcard 正文。
|
||||
|
||||
核心逻辑:与管理端统计口径一致,展示 total/success/skipped/failed 四列计数。
|
||||
核心逻辑:与管理端统计口径一致,展示 total/success/skipped/failed 四列计数;
|
||||
有原始库存归档时提示点击卡片进入 HXOPS(URL 仅放 jump_url,不写进正文)。
|
||||
"""
|
||||
status_label = _WECOM_STATUS_LABEL.get(run.status, run.status)
|
||||
skipped_count = int(run.skipped_count or 0)
|
||||
@@ -93,6 +112,10 @@ def _build_schedule_run_wecom_description(run: ScheduleRun) -> str:
|
||||
summary = run.response_summary_json if isinstance(run.response_summary_json, dict) else {}
|
||||
if summary.get('excel_failed') or summary.get('excel_export_status') == 'failed':
|
||||
description += '\n备注: 库存源已成功,但排程 Excel 生成失败'
|
||||
from app.services.schedule.shipping_inventory_rpa_archive import inventory_raw_zip_available_from_summary
|
||||
|
||||
if inventory_raw_zip_available_from_summary(summary):
|
||||
description += '\n原始库存包:点击本通知进入 HXOPS 下载'
|
||||
return description
|
||||
|
||||
|
||||
@@ -125,7 +148,7 @@ def _notify_schedule_run_wecom(task: ScheduleTask, run: ScheduleRun) -> None:
|
||||
return
|
||||
|
||||
title = f'排程执行结果: {task.name}'
|
||||
description = _build_schedule_run_wecom_description(run)
|
||||
jump_params = _build_schedule_run_wecom_jump_params(task, run)
|
||||
|
||||
media_id = None
|
||||
if run.excel_file_data and run.excel_file_name:
|
||||
@@ -142,7 +165,8 @@ def _notify_schedule_run_wecom(task: ScheduleTask, run: ScheduleRun) -> None:
|
||||
|
||||
for u in wecom_users:
|
||||
trace_id = uuid.uuid4().hex
|
||||
jump_url = _build_jump_url('/workspace', trace_id, {'tab': 'schedule-runs'})
|
||||
jump_url = _build_jump_url('/admin/schedules', trace_id, jump_params)
|
||||
description = _build_schedule_run_wecom_description(run)
|
||||
|
||||
try:
|
||||
audit = _create_audit(_WECOM_EVENT_TYPE, u, title, description, trace_id)
|
||||
@@ -617,8 +641,17 @@ def start_scheduler(app):
|
||||
recovered_awaiting,
|
||||
)
|
||||
|
||||
from app.services.shipping_notice.rpa_worker_heartbeat_alert import maybe_alert_rpa_worker_status
|
||||
maybe_alert_rpa_worker_status(force=True)
|
||||
|
||||
while True:
|
||||
try:
|
||||
from app.services.shipping_notice.rpa_worker_heartbeat_alert import (
|
||||
maybe_alert_rpa_worker_status,
|
||||
)
|
||||
|
||||
maybe_alert_rpa_worker_status()
|
||||
|
||||
now = utc_now_naive()
|
||||
due_tasks = db.session.query(ScheduleTask).filter(
|
||||
ScheduleTask.enabled.is_(True),
|
||||
|
||||
Reference in new issue
Block a user