chore(shipping-notice): 统一货代发货生命周期阶段命名并优化全链路业务逻辑
This commit is contained in:
1 parent
5ef8329bd8
commit
4ec4e57005
183 files changed
+14653
-3936
No files matched your search
@@ -0,0 +1,50 @@
|
||||
"""
|
||||
app/jobs/handlers/shipping_pdf_automark.py
|
||||
|
||||
用途:执行统一 PDF 自动标记 Job,不向调用方暴露 XFA/普通 PDF 分流。
|
||||
依赖:Job 队列、order_document_profile_pdf_automark_service。
|
||||
逻辑:冻结 Job 载荷后委托统一证据管线;成功或受控失败均按通用 Job 契约终态化。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from app.extensions import db
|
||||
from app.jobs.context import JobContext
|
||||
from app.jobs.queue import fail_job, finish_job
|
||||
from app.jobs.registry import register_handler
|
||||
from app.jobs.types import JobType
|
||||
from app.models import Job
|
||||
|
||||
|
||||
@register_handler(JobType.SHIPPING_PDF_AUTOMARK)
|
||||
def run_shipping_pdf_automark(ctx: JobContext, payload: dict) -> None:
|
||||
"""执行统一 PDF 自动标记;任何 PDF 类型均复用同一 Job 生命周期。"""
|
||||
_ = ctx
|
||||
raw_job_id = payload.get('job_id')
|
||||
job = db.session.get(Job, int(raw_job_id)) if raw_job_id else None
|
||||
if job is None:
|
||||
return
|
||||
owned_attempt = int(job.attempts or 0)
|
||||
frozen = dict(job.payload_json or {})
|
||||
frozen.setdefault('job_id', int(job.id))
|
||||
from app.services.shipping_notice import order_document_profile_pdf_automark_service as automark_service
|
||||
try:
|
||||
result = automark_service.execute_pdf_automark_job(frozen)
|
||||
except automark_service.PdfAutomarkError as exc:
|
||||
fail_job(
|
||||
job.id,
|
||||
error=str(exc.message or exc)[:500],
|
||||
result={'status': 'failed', 'error_code': exc.error_code, 'details': dict(exc.details or {})},
|
||||
retryable=bool(exc.retryable),
|
||||
owned_attempt=owned_attempt,
|
||||
)
|
||||
return
|
||||
except Exception as exc: # noqa: BLE001
|
||||
fail_job(
|
||||
job.id,
|
||||
error=str(exc)[:500],
|
||||
result={'status': 'failed', 'error_code': 'SHIPPING.ORDER_DOCUMENT_PROFILE_PDF_AUTOMARK_FAILED'},
|
||||
retryable=True,
|
||||
owned_attempt=owned_attempt,
|
||||
)
|
||||
return
|
||||
finish_job(job.id, result=result, message='PDF automark completed', owned_attempt=owned_attempt)
|
||||
Reference in new issue
Block a user