Merge branch 'hugo-shipping-notice' into dev
# Conflicts: # backend/app/api/__init__.py # backend/app/jobs/types.py # backend/app/models/__init__.py # backend/app/services/schedule/job_registry.py # docs/features/README.md # docs/funclist.md # docs/tec.md # frontend/src/locales/zh-CN/admin.json
This commit is contained in:
commit
dac31e48bd
691 files changed
+53341
-14863
No files matched your search
@@ -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(
|
||||
@@ -1069,12 +1082,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
|
||||
Reference in new issue
Block a user