会员积分改版V8 追加订单自动过期celery定时任务
This commit is contained in:
@@ -32,29 +32,6 @@ async def lifespan(app: FastAPI):
|
||||
await init_redis()
|
||||
# await _seed_data()
|
||||
|
||||
# Background task: auto-expire pending payment orders and sync status
|
||||
async def _order_expiry_loop():
|
||||
from app.services.payment import expire_all_pending_orders, sync_pending_orders
|
||||
from logging import getLogger
|
||||
bg_logger = getLogger("payment")
|
||||
while True:
|
||||
try:
|
||||
async with async_session() as db:
|
||||
# 同步待支付订单状态(检查支付宝实际支付状态
|
||||
sync_count = await sync_pending_orders(db)
|
||||
if sync_count > 0:
|
||||
bg_logger.info(f"Synced {sync_count} pending payment order(s)")
|
||||
|
||||
# 自动过期订单
|
||||
n = await expire_all_pending_orders(db)
|
||||
if n > 0:
|
||||
bg_logger.info(f"Auto-expired {n} pending payment order(s)")
|
||||
except Exception as e:
|
||||
bg_logger.error(f"Order expiry loop error: {e}")
|
||||
await asyncio.sleep(60) # check every minute
|
||||
|
||||
expiry_task = asyncio.create_task(_order_expiry_loop())
|
||||
|
||||
# 启动token刷新定时任务(每5分钟检查一次,小于800秒有效期的token进行刷新)
|
||||
from app.tasks.token_refresh_task import token_refresh_scheduler
|
||||
token_refresh_task = asyncio.create_task(token_refresh_scheduler())
|
||||
@@ -108,7 +85,6 @@ async def lifespan(app: FastAPI):
|
||||
await consumption_queue_task
|
||||
consumption_schedule_task.cancel()
|
||||
pre_test_poll_task.cancel()
|
||||
expiry_task.cancel()
|
||||
token_refresh_task.cancel()
|
||||
await close_database()
|
||||
await close_redis()
|
||||
|
||||
Reference in New Issue
Block a user