fix(app): 修复定时任务同步待支付订单的上下文问题
- 将 sync_pending_orders 增加 app 参数以使用 Flask 应用上下文 - 在函数内部使用 app.app_context() 包裹数据库操作,避免上下文错误 - 保持原有逻辑查询并更新30分钟内的待支付订单状态 - 增加日志记录和异常捕获,确保任务稳定运行 - 调度器调用时传入 app 作为参数以支持上下文执行
This commit is contained in:
parent
1196809c6a
commit
93d5c503b2
4
app.py
4
app.py
@ -15,8 +15,9 @@ import logging
|
||||
import models
|
||||
|
||||
# 定时任务函数
|
||||
def sync_pending_orders():
|
||||
def sync_pending_orders(app):
|
||||
"""定时任务: 检查并同步30分钟内的待支付订单"""
|
||||
with app.app_context():
|
||||
from models import Order, User, get_bj_now
|
||||
from services.alipay_service import AlipayService
|
||||
from services.logger import system_logger
|
||||
@ -181,6 +182,7 @@ def create_app():
|
||||
# 每分钟检查一次待支付订单
|
||||
scheduler.add_job(
|
||||
func=sync_pending_orders,
|
||||
args=[app],
|
||||
trigger=IntervalTrigger(minutes=1),
|
||||
id='sync_pending_orders',
|
||||
name='同步待支付订单',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user