feat(file-check): 新增文件资产管理与清理功能,支持上传、查询、删除及下载

This commit is contained in:
hugo committed 2026-07-14 09:14:44 +08:00
1 parent 143e054d86
commit 729546a7b7
52 files changed
+3420 -34

No files matched your search

+32 -12
View File
@@ -10,7 +10,21 @@ from __future__ import annotations
from typing import Any
from app.jobs.types import QUEUE_KB_JOB_TYPES, JobType, handler_type_for_kb_job
from app.models import KbJob
from app.models import Job, KbJob
def _normalize_generic_job(job: Job) -> dict[str, Any]:
"""将通用 Job ORM 实例转为 runner/handler 使用的归一化任务 dict。"""
job_type_value = str(job.job_type or '').strip()
return {
'id': job.id,
'job_type': JobType(job_type_value),
'raw_job_type': job_type_value,
'payload': {
'job_id': job.id,
**(job.payload_json or {}),
},
}
def _normalize_kb_job(job: KbJob) -> dict[str, Any]:
@@ -59,7 +73,7 @@ def claim_next(*, queues: list[str] | None = None) -> dict[str, Any] | None:
from app.services.knowledge_cleaning.queue_service import recover_stale_running_jobs
recover_stale_running_jobs()
if 'shipping_notice_run' in allowed_types:
if 'shipping_notice_run' in allowed_types or 'shipping_notice_parse' in allowed_types:
from app.services.shipping_notice.queue_service import recover_stale_shipping_notice_jobs
recover_stale_shipping_notice_jobs()
@@ -77,30 +91,36 @@ def claim_next(*, queues: list[str] | None = None) -> dict[str, Any] | None:
job = claim_next_shipping_notice_job()
if job:
return _normalize_kb_job(job)
return _normalize_generic_job(job)
return None
def mark_failed(job_id: int, *, message: str) -> None:
"""
handler 未捕获异常时,将 KbJob 标记为 failed。
handler 未捕获异常时,将任务标记为 failed(KbJob 或通用 Job)。
Args:
job_id: KbJob 主键。
job_id: 任务主键。
message: 失败原因(截断至 1000 字符)。
"""
from datetime import datetime
from app import db
from app.jobs.queue import fail_job
job = db.session.get(KbJob, job_id)
if not job or job.status != 'running':
job = db.session.get(Job, job_id)
if job and job.status == 'running':
fail_job(job, error=message[:1000], retryable=True)
return
kb_job = db.session.get(KbJob, job_id)
if not kb_job or kb_job.status != 'running':
return
now = datetime.utcnow()
job.status = 'failed'
job.error_message = message[:1000]
job.message = message[:500]
job.finished_at = now
job.progress = 100
kb_job.status = 'failed'
kb_job.error_message = message[:1000]
kb_job.message = message[:500]
kb_job.finished_at = now
kb_job.progress = 100
db.session.commit()