fix(计划): 定时触发补 app context;账号状态加检测时间与历史记录
- _fire 内调用 run_plan(修复 18:00 Working outside application context,无运行记录) - device_account 新增 status_checked_at;新表 account_status_log(schema v23) - 每次检测/手改留痕;资产表显示检测时间 + 「记录」弹窗 - API /api/af/account_status_logs;备份标签/文档/测试同步
This commit is contained in:
+7
-4
@@ -1000,15 +1000,18 @@ def _fire(plan_id):
|
||||
"""到点触发(APScheduler 调的,在自己的线程里)。失败只记日志,不冒泡。"""
|
||||
try:
|
||||
from core.models import AePlan
|
||||
# ⚠ `run_plan` 内部要查库/建 AeRun —— **必须在 app context 里调**;
|
||||
# APScheduler 的线程没有请求上下文,之前放在 with 外面会报
|
||||
# "Working outside of application context"(2026-10-21 18:00 实测)。
|
||||
with _ctx():
|
||||
row = AePlan.query.get(plan_id)
|
||||
if row is None or not row.enabled:
|
||||
return
|
||||
plan = row.to_dict()
|
||||
if not _in_date_range(plan) or not _in_window(plan):
|
||||
_log.info("计划 %s 到点但不在日期范围/运行窗口内 → 跳过", plan_id)
|
||||
return
|
||||
res = run_plan(plan_id, trigger="cron")
|
||||
if not _in_date_range(plan) or not _in_window(plan):
|
||||
_log.info("计划 %s 到点但不在日期范围/运行窗口内 → 跳过", plan_id)
|
||||
return
|
||||
res = run_plan(plan_id, trigger="cron")
|
||||
if not res.get("ok"):
|
||||
_log.warning("计划 %s 到点触发失败:%s", plan_id, res.get("error"))
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user