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

30 lines
895 B
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_dify_sync.py
用途:KB 文档同步至 Dify 任务 handler。
逻辑:包装 knowledge_cleaning.tasks.run_sync_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_DIFY_SYNC)
def run_kb_dify_sync(ctx: JobContext, payload: dict) -> None:
"""
同步已清洗文档到 Dify。
Args:
ctx: Worker 上下文。
payload: 须含 job_id(KbJob 主键)。
"""
job_id = int(payload['job_id'])
from app.services.knowledge_cleaning.tasks import run_sync_job
ok, message = run_sync_job(job_id)
level = ctx.logger.info if ok else ctx.logger.warning
level('kb_dify_sync job_id=%s ok=%s message=%s', job_id, ok, message)
if not ok:
raise RuntimeError(message)