feat(shipping-notice): 新增发货通知重复检测与处理接口,支持重复决策保存与重新执行检测
This commit is contained in:
1 parent
729546a7b7
commit
ceb49461e8
72 files changed
+14270
-460
No files matched your search
@@ -20,6 +20,8 @@ def _normalize_generic_job(job: Job) -> dict[str, Any]:
|
||||
'id': job.id,
|
||||
'job_type': JobType(job_type_value),
|
||||
'raw_job_type': job_type_value,
|
||||
# 领取时代次,供异常收口条件 UPDATE(勿信 Session 缓存)
|
||||
'attempts': int(job.attempts or 0),
|
||||
'payload': {
|
||||
'job_id': job.id,
|
||||
**(job.payload_json or {}),
|
||||
@@ -96,21 +98,29 @@ def claim_next(*, queues: list[str] | None = None) -> dict[str, Any] | None:
|
||||
return None
|
||||
|
||||
|
||||
def mark_failed(job_id: int, *, message: str) -> None:
|
||||
def mark_failed(job_id: int, *, message: str, owned_attempt: int | None = None) -> None:
|
||||
"""
|
||||
handler 未捕获异常时,将任务标记为 failed(KbJob 或通用 Job)。
|
||||
|
||||
Args:
|
||||
job_id: 任务主键。
|
||||
message: 失败原因(截断至 1000 字符)。
|
||||
owned_attempt: 领取时的 Job.attempts;通用 Job 用条件 UPDATE,避免覆盖新代次。
|
||||
"""
|
||||
from datetime import datetime
|
||||
|
||||
from app import db
|
||||
from app.jobs.queue import fail_job
|
||||
|
||||
job = db.session.get(Job, job_id)
|
||||
if job and job.status == 'running':
|
||||
fail_job(job, error=message[:1000], retryable=True)
|
||||
# 通用 Job 表命中则条件收口(rowcount=0 即代次/状态已变,安全 no-op)
|
||||
generic = db.session.query(Job.id).filter(Job.id == int(job_id)).first()
|
||||
if generic is not None:
|
||||
fail_job(
|
||||
int(job_id),
|
||||
error=message[:1000],
|
||||
retryable=True,
|
||||
owned_attempt=owned_attempt,
|
||||
)
|
||||
return
|
||||
|
||||
kb_job = db.session.get(KbJob, job_id)
|
||||
|
||||
Reference in new issue
Block a user