fix(automation): 修复账号供给补货队列饥饿
- 拆分订单补货和通用供给水位,供给保留独立 pending 配额 - 每批固定供给槽位,避免订单补货占满队列 - 只补覆盖/可兑换缺口,可分配缺口不再无效入队 - 重登工作超过 24h 自动转人工,清理待处理积压 - 补货阻塞告警和队列诊断信息 - 增加供给公平调度/过期清理回归测试
This commit is contained in:
@@ -21,6 +21,7 @@ from ....models import (
|
||||
)
|
||||
from ...account_sync_runner import ACCOUNT_SYNC_WORK_TYPES, WORK_STOREHOME_SYNC
|
||||
from ...account_work_queue import (
|
||||
SUPPLY_REASON_PREFIX,
|
||||
active_account_work_count,
|
||||
enqueue_account_work,
|
||||
)
|
||||
@@ -66,13 +67,17 @@ def _pending_demand_rows(
|
||||
return list(db.execute(statement).all())
|
||||
|
||||
|
||||
def _queue_target_pending() -> int:
|
||||
def _order_queue_target_pending() -> int:
|
||||
"""订单能力补货自己的水位;通用供给有自己的保留水位。"""
|
||||
import os
|
||||
|
||||
raw = os.getenv("ACCOUNT_ORDER_QUEUE_TARGET_PENDING")
|
||||
if raw is None:
|
||||
raw = os.getenv("ACCOUNT_SYNC_QUEUE_TARGET_PENDING", "70")
|
||||
try:
|
||||
return max(1, int(os.getenv("ACCOUNT_SYNC_QUEUE_TARGET_PENDING", "60")))
|
||||
return max(1, int(raw))
|
||||
except ValueError:
|
||||
return 60
|
||||
return 70
|
||||
|
||||
|
||||
def _build_select_query(
|
||||
@@ -130,8 +135,9 @@ def run_account_capability_refresh(
|
||||
pending = active_account_work_count(
|
||||
db,
|
||||
work_types=ACCOUNT_SYNC_WORK_TYPES,
|
||||
exclude_reason_prefix=SUPPLY_REASON_PREFIX,
|
||||
)
|
||||
headroom = max(0, _queue_target_pending() - pending)
|
||||
headroom = max(0, _order_queue_target_pending() - pending)
|
||||
if headroom <= 0:
|
||||
return {
|
||||
"scanned": 0,
|
||||
@@ -179,6 +185,7 @@ def run_account_capability_refresh(
|
||||
"detail": {
|
||||
"queued": queued,
|
||||
"pending": pending,
|
||||
"order_cap": _order_queue_target_pending(),
|
||||
"headroom": headroom,
|
||||
"commodities": commodity_ids[:20],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user