diff --git a/inventory-backend/run.py b/inventory-backend/run.py index fc8cf07..bb0bb08 100644 --- a/inventory-backend/run.py +++ b/inventory-backend/run.py @@ -1,5 +1,6 @@ # inventory-backend/run.py import sys +from datetime import datetime from app import create_app @@ -54,7 +55,18 @@ def _run_warning_job(): def _run_daily_report_job(): - """MOM 系统日报(每天 17:30 北京时间)""" + """MOM 系统日报(每天 17:30 北京时间,**仅工作日**发送)""" + # ★ 非工作日跳过。判定放在最前面 —— 连 app_context 和抢锁都不进: + # 工作日判定是纯本地计算,不需要数据库,跳过时零开销。 + # 日期必须按**北京时间**取:容器时区通常是 UTC,而北京时间凌晨 0–8 点 + # 对应 UTC 的前一天 16–24 点 —— 此时 date.today() 会拿到前一天。 + # 节假日/调休口径见 app/utils/workday.py。 + from app.utils.workday import is_workday + today = datetime.now(beijing_tz).date() + if not is_workday(today): + print(f"[Scheduler] 系统日报:{today} 非工作日,跳过发送", flush=True) + return + with app.app_context(): from app.utils.job_lock import advisory_lock, LOCK_DAILY_REPORT with advisory_lock(LOCK_DAILY_REPORT) as acquired: @@ -85,7 +97,7 @@ scheduler.add_job( replace_existing=True ) scheduler.start() -print("✅ 定时任务已启动:库存预警 9:30 / MOM系统日报 17:30(北京时间)", flush=True) +print("✅ 定时任务已启动:库存预警 9:30(每日)/ MOM系统日报 17:30(仅工作日,北京时间)", flush=True) if __name__ == '__main__': # =================================================