fix(rohs-check): 修复检核任务禁用状态处理及错误信息
This commit is contained in:
1 parent
25cc87fdb3
commit
3068e3abb4
15 files changed
+1407
-13
No files matched your search
@@ -13,7 +13,7 @@ from flask import Blueprint, current_app, jsonify, request, send_file
|
||||
from sqlalchemy import text
|
||||
|
||||
from app import db
|
||||
from app.errors import AppError, ConflictError, NotFoundError, ServiceUnavailableError, UnauthorizedError, ValidationError
|
||||
from app.errors import AppError, ConflictError, NotFoundError, ServiceUnavailableError, UnauthorizedError
|
||||
from app.models import ScheduleRun, ScheduleTask
|
||||
from app.services.hxops_tool_api import resolve_hxops_tool_api_base
|
||||
from app.services.rohs_check_tools.openapi_spec import build_rohs_openapi_spec
|
||||
@@ -76,7 +76,6 @@ def _tool_error_code(exc: AppError) -> str:
|
||||
"missing_auth",
|
||||
"invalid_auth",
|
||||
"task_not_found",
|
||||
"task_disabled",
|
||||
"run_not_found",
|
||||
"excel_not_ready",
|
||||
"kb_sync_failed",
|
||||
@@ -223,10 +222,9 @@ def list_rohs_tasks():
|
||||
|
||||
@rohs_check_bp.route("/tools/tasks/run", methods=["POST"])
|
||||
def run_rohs_check():
|
||||
"""立即执行检核;任务 enabled 仅控制 cron,不限制人工或 Chatflow 触发。"""
|
||||
data = request.get_json(silent=True) or {}
|
||||
task = _resolve_check_task(data)
|
||||
if not task.enabled:
|
||||
raise ValidationError("task_disabled")
|
||||
|
||||
with _RUN_START_LOCK:
|
||||
_acquire_task_start_lock(task.id)
|
||||
|
||||
@@ -328,14 +328,14 @@
|
||||
}
|
||||
},
|
||||
"BadRequest": {
|
||||
"description": "请求无效或检核任务已停用",
|
||||
"description": "请求参数无效",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": { "$ref": "#/components/schemas/ErrorResponse" },
|
||||
"example": {
|
||||
"ok": false,
|
||||
"error_code": "task_disabled",
|
||||
"message": "task_disabled"
|
||||
"error_code": "invalid_request",
|
||||
"message": "invalid_request"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -208,7 +208,20 @@ def test_rohs_tool_excel_download_uses_signed_token(app, client):
|
||||
assert res.status_code == 401
|
||||
|
||||
|
||||
def test_rohs_tool_task_disabled(app, client):
|
||||
def test_rohs_tool_runs_disabled_schedule_immediately(app, client, monkeypatch):
|
||||
started_threads = []
|
||||
|
||||
class _Thread:
|
||||
def __init__(self, *, target, daemon, name):
|
||||
self.target = target
|
||||
self.daemon = daemon
|
||||
self.name = name
|
||||
|
||||
def start(self):
|
||||
started_threads.append(self.name)
|
||||
|
||||
monkeypatch.setattr('app.api.rohs_check_tools.threading.Thread', _Thread)
|
||||
|
||||
with app.app_context():
|
||||
app.config['INTEGRATION_API_KEY'] = 'secret'
|
||||
admin = _mk_admin()
|
||||
@@ -221,8 +234,12 @@ def test_rohs_tool_task_disabled(app, client):
|
||||
headers={'X-Integration-Key': 'secret', 'Content-Type': 'application/json'},
|
||||
json={'task_id': task_id},
|
||||
)
|
||||
assert res.status_code == 400
|
||||
assert res.get_json()['error_code'] == 'task_disabled'
|
||||
assert res.status_code == 200
|
||||
data = res.get_json()
|
||||
assert data['ok'] is True
|
||||
assert data['run']['task_id'] == task_id
|
||||
assert data['run']['status'] == 'running'
|
||||
assert started_threads == [f"rohs-check-run-{data['run']['run_id']}"]
|
||||
|
||||
|
||||
def test_rohs_openapi_injects_tool_api_base(app, client):
|
||||
|
||||
@@ -571,7 +571,7 @@
|
||||
}
|
||||
},
|
||||
"BadRequest": {
|
||||
"description": "请求无效或检核任务已停用",
|
||||
"description": "请求参数无效",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
@@ -579,8 +579,8 @@
|
||||
},
|
||||
"example": {
|
||||
"ok": false,
|
||||
"error_code": "task_disabled",
|
||||
"message": "task_disabled"
|
||||
"error_code": "invalid_request",
|
||||
"message": "invalid_request"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user