Merge branch 'dev' into hugo-shipping-notice
This commit is contained in:
commit
472b530be3
397 files changed
+46450
-34171
No files matched your search
@@ -5,21 +5,4 @@ backend/app/jobs/handlers/__init__.py
|
||||
逻辑:Wave 2 起在 worker 启动前 import 本包。
|
||||
"""
|
||||
|
||||
from app.jobs.handlers import ( # noqa: F401
|
||||
file_check_run,
|
||||
kb_clean,
|
||||
kb_dify_sync,
|
||||
schedule_run,
|
||||
shipping_document_layout,
|
||||
shipping_notice_parse,
|
||||
shipping_notice_run,
|
||||
shipping_order_extraction,
|
||||
shipping_process_gate,
|
||||
shipping_auto_progress,
|
||||
shipping_stp_auto_create,
|
||||
shipping_line_auto_fulfill,
|
||||
shipping_post_ot_wave_progress,
|
||||
shipping_review_revalidate_progress,
|
||||
shipping_xfa_ocr_automark,
|
||||
wecom_directory_sync,
|
||||
)
|
||||
from app.jobs.handlers import file_check_run, kb_clean, kb_dify_sync, procurement_contract_review, schedule_run, shipping_notice_parse, shipping_notice_run, wecom_directory_sync # noqa: F401
|
||||
@@ -0,0 +1,48 @@
|
||||
"""
|
||||
backend/app/jobs/handlers/procurement_contract_review.py
|
||||
|
||||
用途:采购合同清洗、确定性分析与 Dify 全面审核的异步任务处理器。
|
||||
依赖:jobs.registry、models.Job、procurement_contract.review_service。
|
||||
逻辑:contract 队列领取任务后按 review_no 执行审核;仅在重试次数耗尽时把业务审核标记为 failed。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from app import db
|
||||
from app.jobs.context import JobContext
|
||||
from app.jobs.queue import finish_job
|
||||
from app.jobs.registry import register_handler
|
||||
from app.jobs.types import JobType
|
||||
from app.models import Job
|
||||
from app.services.procurement_contract import review_service
|
||||
|
||||
|
||||
@register_handler(JobType.PROCUREMENT_CONTRACT_REVIEW)
|
||||
def run_procurement_contract_review(ctx: JobContext, payload: dict) -> None:
|
||||
"""
|
||||
执行一份采购合同后台审核。
|
||||
|
||||
Args:
|
||||
ctx: Worker 上下文,用于记录运行日志。
|
||||
payload: 必须包含 review_no;job_id 由通用队列注入。
|
||||
|
||||
Raises:
|
||||
RuntimeError: 审核失败时抛出,由通用队列决定重试或终态失败。
|
||||
"""
|
||||
review_no = str(payload.get("review_no") or "").strip()
|
||||
job_id = int(payload.get("job_id") or 0)
|
||||
if not review_no or not job_id:
|
||||
raise RuntimeError("review_no and job_id are required")
|
||||
try:
|
||||
result = review_service.execute_review_job(review_no=review_no, job_id=job_id)
|
||||
finish_job(job_id, result={"review_no": review_no, "status": "success"}, message="合同审核完成")
|
||||
ctx.logger.info("contract review completed review_no=%s job_id=%s", review_no, job_id)
|
||||
except Exception as exc:
|
||||
db.session.rollback()
|
||||
job = db.session.get(Job, job_id)
|
||||
if job and int(job.attempts or 0) >= int(job.max_attempts or 1):
|
||||
review_service.mark_review_failed(review_no=review_no, error=str(exc))
|
||||
else:
|
||||
review_service.mark_review_retrying(review_no=review_no, error=str(exc))
|
||||
ctx.logger.exception("contract review failed review_no=%s job_id=%s", review_no, job_id)
|
||||
raise
|
||||
@@ -2,17 +2,31 @@
|
||||
backend/app/jobs/handlers/schedule_run.py
|
||||
|
||||
用途:排程任务执行 handler。
|
||||
逻辑:Wave 4 从 scheduler_service in-process 执行体迁入。
|
||||
依赖:schedule.queue_service、jobs registry/context。
|
||||
逻辑:独立 schedule worker 领取 Job 后,委托 queue_service 执行并同步双层状态。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from app.jobs.context import JobContext
|
||||
from app.jobs.registry import register_handler
|
||||
from app.jobs.types import JobType
|
||||
from app.services.schedule.queue_service import execute_schedule_job
|
||||
|
||||
|
||||
@register_handler(JobType.SCHEDULE_RUN)
|
||||
def run_schedule(ctx: JobContext, payload: dict) -> None:
|
||||
"""执行单条 ScheduleTask。"""
|
||||
ctx.logger.info('schedule_run handler skeleton invoked payload=%s', payload)
|
||||
raise NotImplementedError('schedule_run handler pending Wave 4')
|
||||
"""
|
||||
执行单条已入队排程。
|
||||
|
||||
Args:
|
||||
ctx: Worker 上下文,用于日志与运行配置。
|
||||
payload: 必须包含 job_id 与 schedule_run_id。
|
||||
|
||||
Raises:
|
||||
RuntimeError: payload 缺失或执行失败时抛出,由通用 Job 层负责重试。
|
||||
"""
|
||||
job_id = int(payload.get("job_id") or 0)
|
||||
run_id = int(payload.get("schedule_run_id") or 0)
|
||||
if not job_id or not run_id:
|
||||
raise RuntimeError("job_id and schedule_run_id are required")
|
||||
execute_schedule_job(job_id=job_id, run_id=run_id, logger=ctx.logger)
|
||||
Reference in new issue
Block a user