27 lines
949 B
Python
27 lines
949 B
Python
"""地磅计划按月自动生成定时任务"""
|
|
import logging
|
|
|
|
from app.core.database import SessionLocal
|
|
from app.services.db.auto_generate_plans import run_auto_generate_monthly_plans
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def auto_generate_monthly_plans_job():
|
|
"""每月 1 日凌晨执行:按上月计划模板生成本月计划。"""
|
|
db = SessionLocal()
|
|
try:
|
|
logger.info("======== 开始执行地磅计划按月自动生成任务 ========")
|
|
result = run_auto_generate_monthly_plans(db, force=False)
|
|
logger.info(
|
|
"======== 地磅计划按月自动生成任务完成:created=%s, month=%s, skipped=%s ========",
|
|
result.get("created_count"),
|
|
result.get("current_month"),
|
|
result.get("skipped_reason"),
|
|
)
|
|
except Exception:
|
|
db.rollback()
|
|
logger.exception("地磅计划按月自动生成任务异常")
|
|
finally:
|
|
db.close()
|