feat(shipping-notice): 收敛订单处理状态与履约门禁

This commit is contained in:
hugo committed 2026-09-07 09:42:12 +08:00
1 parent bffcd55b40
commit 70dd0051b8
153 files changed
+10916 -4296

No files matched your search

+18 -5
View File
@@ -23,7 +23,7 @@ from sqlalchemy.exc import IntegrityError, OperationalError
from sqlalchemy.orm import Session
from app import db
from app.core.errors import ValidationError
from app.core.errors import AppError, NotFoundError, ValidationError
from app.jobs.types import JobType
from app.models import Job
@@ -43,6 +43,19 @@ def _orm_session() -> Session:
return db.session()
def _is_retryable_exc(exc: BaseException) -> bool:
"""按异常类型分级判断任务失败是否可重试(通用裁定,不区分业务域)。
业务 NotFound / AppError.retryable=False(含 ValidationError)视为不可再排队;
仅瞬时基础设施异常(503 ServiceUnavailable 或未归类异常)才允许重试。
"""
if isinstance(exc, NotFoundError):
return False
if isinstance(exc, AppError):
return bool(getattr(exc, 'retryable', False))
return True
def _ensure_outer_dbapi_transaction(session: Session) -> None:
"""
确保 begin_nested() 不会成为数据库最外层事务。
@@ -582,7 +595,7 @@ def recover_stale_jobs(
sibling: Job | None = None
rowcount = 0
if str(domain or '') != 'shipping_notice' and snap_attempts < max_attempts:
if snap_attempts < max_attempts:
if _subject_to_parse_queued_unique(str(job.job_type or "")):
try:
sibling = _resolve_safe_supersede_sibling(
@@ -1054,12 +1067,12 @@ def process_next_job(
return True, job_type_value
except Exception as exc:
db.session.rollback()
# 发货通知失败必须停在当前 Gate,不能由通用 runner 隐式重新入队。
# 其它领域维持既有技术重试策略。
# 失败收口的可重试性由异常类型分级裁定,不按业务域一刀切;
# handler 已自行 fail_job 收敛的绝不应进入此处,此处仅兜底 handler 逃逸的异常。
fail_job(
job_id,
error=str(exc),
retryable=(str(domain or '').strip() != 'shipping_notice'),
retryable=_is_retryable_exc(exc),
owned_attempt=owned_attempt,
)
raise