Files
syops/backend/app/jobs/handlers/kb_clean.py
T

36 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
backend/app/jobs/handlers/kb_clean.py
用途:KB 文档清洗 / 路径上传任务 handler。
逻辑:包装 knowledge_cleaning.tasks.run_clean_job / run_path_upload_job。
"""
from __future__ import annotations
from app.jobs.context import JobContext
from app.jobs.registry import register_handler
from app.jobs.types import JobType
@register_handler(JobType.KB_CLEAN)
def run_kb_clean(ctx: JobContext, payload: dict) -> None:
"""
执行单条 KB 清洗或路径上传任务。
Args:
ctx: Worker 上下文。
payload: 须含 job_id;raw_job_type 为 path_upload 时走路径上传分支。
"""
job_id = int(payload['job_id'])
raw_type = str(payload.get('raw_job_type') or 'clean').strip()
from app.services.knowledge_cleaning.tasks import run_clean_job, run_path_upload_job
if raw_type == 'path_upload':
ok, message = run_path_upload_job(job_id)
else:
ok, message = run_clean_job(job_id)
level = ctx.logger.info if ok else ctx.logger.warning
level('kb_clean job_id=%s raw_type=%s ok=%s message=%s', job_id, raw_type, ok, message)
if not ok:
raise RuntimeError(message)