feat(scheduler): MOM 日报改为仅工作日发送

在 _run_daily_report_job 入口加工作日闸门,位于抢锁与 app_context 之前,非工作日跳过零开销。日期按北京时间取,避免容器 UTC 时区在凌晨算错一天。库存预警 9:30 维持每日发送不变。
This commit is contained in:
yueli
2026-10-03 09:48:40 +08:00
parent 27ac1e4e82
commit de528a5ffd

View File

@ -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__':
# =================================================