Commit ed81e252 by imwangxiaozhou

feat(async-task,api,celery): 完善异步任务取消功能与筛选参数支持

实现CHG-035需求:为单个、批量、全部异步任务取消操作添加Celery Revoke逻辑,移除Redis队列中的已取消任务消息,避免被Worker重复消费
扩展取消全部异步任务接口,新增status/biz_type/task_id/时间范围筛选参数,前后端完成全流程适配
优化Celery事件循环实现,改为线程本地循环以支持多线程Worker模式
调整Celery Worker启动配置,切换为threads模式并设置并发数为4,新增数据库连接池配置
优化异步任务与调用记录的批量更新逻辑,改为批量SQL更新而非单条循环更新,提升处理效率
优化调用记录列表查询逻辑,拆分COUNT查询与数据查询,排除大字段返回提升性能
新增.dockerignore文件,完善项目忽略规则
更新所有相关的设计文档、API规范与操作流程文档
1 parent 49171d3b
**/node_modules
.git
__pycache__
*.pyc
.env
dist
*.log
......@@ -32,9 +32,19 @@ async def batch_cancel_tasks(data: BatchCancelRequest, db: AsyncSession = Depend
@router.post("/cancel-all")
async def cancel_all_tasks(db: AsyncSession = Depends(get_db)):
"""取消全部 pending/processing 状态的异步任务,同步更新关联调用记录。内部分批处理。"""
result = await async_task_service.cancel_all_tasks(db)
async def cancel_all_tasks(
status: Optional[str] = Query(None, description="按状态筛选,不传则取消所有 pending/processing"),
biz_type: Optional[str] = Query(None, description="按业务编码筛选"),
task_id: Optional[str] = Query(None, description="按 celery_task_id 模糊搜索"),
start_time: Optional[str] = Query(None, description="筛选 submitted_at >= start_time"),
end_time: Optional[str] = Query(None, description="筛选 submitted_at <= end_time"),
db: AsyncSession = Depends(get_db),
):
"""取消筛选条件下的异步任务(不传筛选条件时取消全部 pending/processing 任务),同步更新关联调用记录。"""
result = await async_task_service.cancel_all_tasks(
db, status=status, biz_type=biz_type, task_id=task_id,
start_time=start_time, end_time=end_time,
)
return result
......
......@@ -9,6 +9,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
from app.models.async_task import AsyncTask
from app.models.call_record import CallRecord
from app.schemas.async_task import AsyncTaskCreate, AsyncTaskUpdate
from app.celery_app import celery_app
logger = logging.getLogger(__name__)
......@@ -167,6 +168,15 @@ async def cancel_task(db: AsyncSession, task_id: str) -> Optional[dict]:
await db.flush()
await db.refresh(task)
logger.info(f"异步任务已取消: id={task_id}, 关联调用记录已同步为 cancelled")
# 从 Redis 队列移除消息,避免 Worker 仍消费该任务
if task.celery_task_id:
try:
celery_app.control.revoke(task.celery_task_id, terminate=False)
logger.info(f"已从 Redis 队列撤销任务: celery_task_id={task.celery_task_id}")
except Exception as e:
logger.warning(f"撤销任务失败(celery_task_id={task.celery_task_id}): {e}")
return _to_task_dict(task)
......@@ -198,37 +208,89 @@ async def batch_cancel_tasks(db: AsyncSession, task_ids: list[str]) -> dict:
}
async def cancel_all_tasks(db: AsyncSession) -> dict:
"""取消全部 pending/processing 状态的异步任务,分批处理"""
async def cancel_all_tasks(
db: AsyncSession,
status: Optional[str] = None,
biz_type: Optional[str] = None,
task_id: Optional[str] = None,
start_time: Optional[str] = None,
end_time: Optional[str] = None,
) -> dict:
"""取消筛选条件下的异步任务(不传筛选条件时取消全部 pending/processing 任务),分批批量处理"""
total_cancelled = 0
batch_count = 0
BATCH_SIZE = 100
# 默认只取消 pending/processing 状态
status_filter = status if status else ["pending", "processing"]
while True:
result = await db.execute(
select(AsyncTask)
.where(AsyncTask.status.in_(["pending", "processing"]))
.limit(BATCH_SIZE)
# 1. 查出当前批次的待取消任务 ID、celery_task_id 及关联 call_record_id
query = select(AsyncTask.id, AsyncTask.call_record_id, AsyncTask.celery_task_id).join(
CallRecord, AsyncTask.call_record_id == CallRecord.id, isouter=True
)
tasks = result.scalars().all()
if not tasks:
conditions = []
if isinstance(status_filter, list):
conditions.append(AsyncTask.status.in_(status_filter))
else:
conditions.append(AsyncTask.status == status_filter)
if biz_type:
conditions.append(CallRecord.biz_type == biz_type)
if task_id:
conditions.append(
or_(
AsyncTask.id.like(f"%{task_id}%"),
AsyncTask.celery_task_id.like(f"%{task_id}%"),
)
)
if start_time:
conditions.append(AsyncTask.submitted_at >= start_time)
if end_time:
conditions.append(AsyncTask.submitted_at <= end_time)
query = query.where(and_(*conditions)).limit(BATCH_SIZE)
result = await db.execute(query)
rows = result.all()
if not rows:
break
for task in tasks:
task.status = "cancelled"
task.completed_at = datetime.now()
total_cancelled += 1
task_ids = [r.id for r in rows]
celery_task_ids = [r.celery_task_id for r in rows if r.celery_task_id]
call_record_ids = [r.call_record_id for r in rows if r.call_record_id]
# 同步更新关联调用记录
call_result = await db.execute(
select(CallRecord).where(CallRecord.id == task.call_record_id)
# 2. 批量更新 async_tasks(一条 SQL)
now = datetime.now()
await db.execute(
update(AsyncTask)
.where(AsyncTask.id.in_(task_ids))
.values(status="cancelled", completed_at=now)
)
# 3. 批量更新关联 call_records(一条 SQL)
if call_record_ids:
await db.execute(
update(CallRecord)
.where(
CallRecord.id.in_(call_record_ids),
CallRecord.status == "pending",
)
.values(status="cancelled")
)
call_record = call_result.scalar_one_or_none()
if call_record and call_record.status == "pending":
call_record.status = "cancelled"
# 4. 批量从 Redis 队列撤销任务消息
if celery_task_ids:
try:
celery_app.control.revoke(celery_task_ids, terminate=False)
logger.info(f"第 {batch_count + 1} 批已从 Redis 队列撤销 {len(celery_task_ids)} 个任务")
except Exception as e:
logger.warning(f"第 {batch_count + 1} 批撤销任务失败: {e}")
total_cancelled += len(task_ids)
batch_count += 1
logger.info(f"取消全部 - 第 {batch_count} 批完成, 本批取消 {len(tasks)} 个任务")
logger.info(f"取消全部 - 第 {batch_count} 批完成, 本批取消 {len(task_ids)} 个任务")
await db.flush()
logger.info(f"取消全部完成: total={total_cancelled}, batch_count={batch_count}")
......
......@@ -160,6 +160,30 @@ async def get_call(db: AsyncSession, call_id: str) -> Optional[dict]:
)
def _to_list_dict(row) -> dict:
"""将列表查询的行转换为 dict(排除 request_body/response_body 大字段)"""
return {
"id": row.id,
"request_md5": row.request_md5,
"account_id": row.account_id,
"provider_id": row.provider_id,
"model_name": row.model_name,
"account_name": row.account_name,
"biz_type": row.biz_type,
"template_id": row.template_id,
"sensitive_replacements": getattr(row, "sensitive_replacements", None),
"prompt_tokens": row.prompt_tokens,
"completion_tokens": row.completion_tokens,
"total_tokens": row.total_tokens,
"duration_ms": row.duration_ms,
"status": row.status,
"error_message": row.error_message,
"called_at": row.called_at.isoformat() if row.called_at else None,
"created_at": row.created_at.isoformat() if row.created_at else None,
"updated_at": row.updated_at.isoformat() if row.updated_at else None,
}
async def list_calls(
db: AsyncSession,
page: int = 1,
......@@ -171,11 +195,8 @@ async def list_calls(
start_time: Optional[str] = None,
end_time: Optional[str] = None,
) -> dict:
"""分页查询调用记录列表"""
query = select(CallRecord, ModelAccountConfig.account_name).outerjoin(
ModelAccountConfig,
CallRecord.account_id == ModelAccountConfig.id,
)
"""分页查询调用记录列表(优化版:COUNT 不 JOIN,列表不返回 request_body/response_body 大字段)"""
# 构建筛选条件(仅 CallRecord 表字段)
conditions = []
if model_name:
......@@ -184,26 +205,76 @@ async def list_calls(
conditions.append(CallRecord.status == status)
if biz_type:
conditions.append(CallRecord.biz_type == biz_type)
if account_name:
conditions.append(ModelAccountConfig.account_name == account_name)
if start_time:
conditions.append(CallRecord.called_at >= start_time)
if end_time:
conditions.append(CallRecord.called_at <= end_time)
# ====== COUNT ======
# 无 account_name 筛选时,单表 COUNT 即可,避免 LEFT JOIN
count_query = select(func.count(CallRecord.id)).select_from(CallRecord)
if account_name:
count_query = count_query.outerjoin(
ModelAccountConfig,
CallRecord.account_id == ModelAccountConfig.id,
)
conditions.append(ModelAccountConfig.account_name == account_name)
if conditions:
query = query.where(and_(*conditions))
count_query = count_query.where(and_(*conditions))
count_query = select(func.count()).select_from(query.subquery())
total_result = await db.execute(count_query)
total = total_result.scalar() or 0
query = query.order_by(CallRecord.called_at.desc())
query = query.offset((page - 1) * page_size).limit(page_size)
# ====== 数据查询 ======
# 只查询列表需要的字段,排除 request_body/response_body 大字段
data_query = select(
CallRecord.id,
CallRecord.request_md5,
CallRecord.account_id,
CallRecord.provider_id,
CallRecord.model_name,
CallRecord.biz_type,
CallRecord.template_id,
CallRecord.sensitive_replacements,
CallRecord.prompt_tokens,
CallRecord.completion_tokens,
CallRecord.total_tokens,
CallRecord.duration_ms,
CallRecord.status,
CallRecord.error_message,
CallRecord.called_at,
CallRecord.created_at,
CallRecord.updated_at,
ModelAccountConfig.account_name,
).outerjoin(
ModelAccountConfig,
CallRecord.account_id == ModelAccountConfig.id,
)
data_conditions = []
if model_name:
data_conditions.append(CallRecord.model_name == model_name)
if status:
data_conditions.append(CallRecord.status == status)
if biz_type:
data_conditions.append(CallRecord.biz_type == biz_type)
if account_name:
data_conditions.append(ModelAccountConfig.account_name == account_name)
if start_time:
data_conditions.append(CallRecord.called_at >= start_time)
if end_time:
data_conditions.append(CallRecord.called_at <= end_time)
if data_conditions:
data_query = data_query.where(and_(*data_conditions))
data_query = data_query.order_by(CallRecord.called_at.desc())
data_query = data_query.offset((page - 1) * page_size).limit(page_size)
result = await db.execute(query)
rows = result.all() # list of tuples (CallRecord, account_name | None)
items = [_to_call_dict(record, account_name=account_name) for record, account_name in rows]
result = await db.execute(data_query)
rows = result.all()
items = [_to_list_dict(row) for row in rows]
return {
"items": items,
......
......@@ -4,6 +4,7 @@ import logging
from datetime import datetime
from typing import Optional
from functools import wraps
import threading
from celery import Task
from sqlalchemy import select, update
......@@ -211,23 +212,24 @@ async def _process_call(async_task_id: str) -> dict:
}
# 共享事件循环 — Celery 同步进程中复用同一个循环,避免 asyncio.run() 创建/销毁导致的"attached to a different loop" 错误
_shared_loop: Optional[asyncio.AbstractEventLoop] = None
# 线程本地事件循环 — 每个线程独立一个循环,避免 -P threads 模式下多线程争抢
_thread_local = threading.local()
def _run_async(coro):
"""在共享事件循环中运行 async 协程并返回结果"""
global _shared_loop
"""在线程本地的事件循环中运行 async 协程,支持多线程并发"""
try:
_shared_loop = asyncio.get_running_loop()
loop = asyncio.get_running_loop()
# 当前已有循环(如调试或测试环境),直接运行
return _shared_loop.run_until_complete(coro)
return loop.run_until_complete(coro)
except RuntimeError:
# 没有运行中的循环,创建/复用共享循环
if _shared_loop is None or _shared_loop.is_closed():
_shared_loop = asyncio.new_event_loop()
asyncio.set_event_loop(_shared_loop)
return _shared_loop.run_until_complete(coro)
# 没有运行中的循环,获取当前线程的私有循环
loop = getattr(_thread_local, "loop", None)
if loop is None or loop.is_closed():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
_thread_local.loop = loop
return loop.run_until_complete(coro)
@celery_app.task(
......
......@@ -24,7 +24,7 @@ services:
build: .
container_name: llm-call-platform-celery
entrypoint: [""]
command: celery -A app.celery_app worker -l info -P solo
command: celery -A app.celery_app worker -l info -P threads --concurrency=4
environment:
- LLMCP_DB_HOST=192.168.3.92
- LLMCP_DB_PORT=3308
......@@ -37,6 +37,7 @@ services:
- LLMCP_LOG_STORAGE_PATH=/app/logs
- LLMCP_CELERY_BROKER_URL=redis://192.168.3.209:6379/0
- LLMCP_CELERY_RESULT_BACKEND=redis://192.168.3.209:6379/1
- LLMCP_DB_POOL_SIZE=4
volumes:
- ./logs:/app/logs
restart: unless-stopped
......@@ -253,17 +253,25 @@ function handleBatchCancel(taskIds: string[], setTaskIds: (ids: string[]) => voi
});
}
function handleCancelAll() {
function handleCancelAll(filters?: {
status?: string;
biz_type?: string;
task_id?: string;
start_time?: string;
end_time?: string;
}) {
const hasFilters = filters && Object.values(filters).some(v => v !== undefined);
const filterDesc = hasFilters ? '当前筛选条件下的' : '所有';
Modal.confirm({
title: '取消全部任务',
content: '确定要取消所有等待中和处理中的任务吗?此操作不可撤销。',
content: `确定要取消${filterDesc}等待中和处理中的任务吗?此操作不可撤销。`,
okText: '取消全部',
okType: 'danger',
cancelText: '返回',
onOk: async () => {
try {
const result = await useAsyncTaskStore.getState().cancelAllTasks();
message.success(`已取消全部 ${result.total} 个任务${result.batch_count ? `(分 ${result.batch_count} 批处理)` : ''}`);
const result = await useAsyncTaskStore.getState().cancelAllTasks(filters);
message.success(`已取消 ${result.total} 个任务${result.batch_count ? `(分 ${result.batch_count} 批处理)` : ''}`);
} catch {
message.error('取消全部失败');
}
......@@ -549,7 +557,7 @@ export default function CallMonitor() {
<Button
icon={<MinusCircleOutlined />}
danger
onClick={handleCancelAll}
onClick={() => handleCancelAll(buildTaskFilterParams())}
>
取消全部
</Button>
......
......@@ -19,6 +19,12 @@ export const asyncTaskService = {
batchCancel: (taskIds: string[]) =>
api.post<CancelResult>('/v1/async-tasks/batch-cancel', { task_ids: taskIds }).then((r) => r.data),
cancelAll: () =>
api.post<CancelResult>('/v1/async-tasks/cancel-all').then((r) => r.data),
cancelAll: (params?: {
status?: string;
biz_type?: string;
task_id?: string;
start_time?: string;
end_time?: string;
}) =>
api.post<CancelResult>('/v1/async-tasks/cancel-all', null, { params }).then((r) => r.data),
};
......@@ -63,8 +63,14 @@ export const useAsyncTaskStore = create<AsyncTaskState>((set, get) => ({
return result;
},
cancelAllTasks: async () => {
const result = await asyncTaskService.cancelAll();
cancelAllTasks: async (params?: {
status?: string;
biz_type?: string;
task_id?: string;
start_time?: string;
end_time?: string;
}) => {
const result = await asyncTaskService.cancelAll(params);
await get().fetchTasks();
return result;
},
......
......@@ -29,7 +29,7 @@
{"type": "list_task", "desc": "按状态/时间范围分页查询异步任务列表", "endpoint": "GET /api/v1/async-tasks"},
{"type": "cancel_task", "desc": "取消正在执行的异步任务,同时将关联调用记录标记为 cancelled", "endpoint": "POST /api/v1/async-tasks/:task_id/cancel"},
{"type": "cancel_batch", "desc": "批量取消多个异步任务,同时将关联调用记录标记为 cancelled。分批处理以支持取消任意数量任务", "endpoint": "POST /api/v1/async-tasks/batch-cancel"},
{"type": "cancel_all", "desc": "取消当前所有 pending/processing 状态的异步任务,同时将关联调用记录标记为 cancelled。分批处理以支持取消全部任务", "endpoint": "POST /api/v1/async-tasks/cancel-all"},
{"type": "cancel_all", "desc": "<b>CHG-035</b>:取消当前所有 pending/processing 状态的异步任务(支持按筛选条件),取消时同步更新关联调用记录 + 调用 Celery Revoke 从 Redis 队列移除消息。分批处理以支持取消全部任务。", "endpoint": "POST /api/v1/async-tasks/cancel-all"},
{"type": "show_variables", "desc": "<b>CHG-030</b>:调用详情展示输入变量及其值,支持一键复制变量值。前端从 template_info 模板内容中解析 {{xxx}} 占位符,与 request_body 中的实际文本匹配提取变量值。无需数据库新增字段。", "endpoint": "GET /api/v1/calls/:id(已有接口)"},
{"type": "filter_calls", "desc": "<b>CHG-032</b>:调用记录列表支持业务编码、状态、账号、模型、时间范围筛选。异步任务列表支持状态和提交时间范围筛选。", "endpoint": "GET /api/v1/calls(增强)、GET /api/v1/async-tasks(增强)"}
],
......@@ -105,6 +105,14 @@
"title": "调用记录和异步任务列表新增筛选功能",
"desc": "1. 调用记录列表新增业务编码(biz_type)、状态(status)、账号(account_name)、模型(model_name)、时间范围(start_time/end_time)筛选\n2. 异步任务列表新增状态筛选增强、提交时间范围筛选\n3. 前端 CallMonitor 页面两个 Tab 均新增筛选栏\n4. API:GET /api/v1/calls 新增 account_name/start_time/end_time 查询参数;GET /api/v1/async-tasks 新增 start_time/end_time 查询参数",
"done": true
},
{
"date": "2026-07-03",
"id": "CHG-035",
"type": "modify",
"title": "取消任务时同步调用 Celery Revoke 移除 Redis 队列消息",
"desc": "取消单个/批量/全部异步任务时,在更新 DB 状态后同步调用 celery_app.control.revoke() 从 Redis 队列移除消息。取消全部接口新增筛选参数(status/biz_type/task_id/start_time/end_time)。",
"done": true
}
]
}
......@@ -473,6 +473,14 @@
"title": "异步任务列表新增业务编码筛选",
"desc": "异步任务列表新增业务编码筛选控件,GET /api/v1/async-tasks 新增 biz_type 查询参数(联表 call_records 按 biz_type 过滤)。前端异步任务筛选栏新增业务编码 Select 下拉框。",
"done": true
},
{
"date": "2026-07-03",
"id": "CHG-035",
"type": "modify",
"title": "取消任务时同步调用 Celery Revoke 移除 Redis 队列消息",
"desc": "取消单个/批量/全部异步任务时,在更新 DB 状态后同步调用 celery_app.control.revoke(celery_task_id, terminate=False) 从 Redis 队列移除消息,避免已取消的任务仍被 Worker 消费。取消全部接口新增筛选参数支持(status/biz_type/task_id/start_time/end_time)。F-04 → done。",
"done": true
}
]
}
\ No newline at end of file
......@@ -484,6 +484,10 @@
"text": "更新关联 call_records 表:status=cancelled"
},
{
"tag": "write",
"text": "调用 celery_app.control.revoke(celery_task_id, terminate=False) 从 Redis 队列移除消息"
},
{
"tag": "return",
"text": "返回操作结果"
}
......@@ -492,7 +496,7 @@
"任务状态更新为 cancelled",
"关联调用记录状态更新为 cancelled"
],
"changelog": {"id": "CHG-026", "date": "2026-06-25", "reason": "取消任务时同步更新调用记录状态为 cancelled"}
"changelog": {"id": "CHG-035", "date": "2026-07-03", "reason": "取消任务时同步更新调用记录状态为 cancelled + 调用 Celery Revoke 移除 Redis 队列消息"}
}
]
},
......@@ -541,6 +545,10 @@
"text": "逐批更新关联 call_records:status=cancelled"
},
{
"tag": "write",
"text": "逐批调用 celery_app.control.revoke(celery_task_id, terminate=False) 从 Redis 队列移除消息"
},
{
"tag": "return",
"text": "返回取消结果统计(total/成功/失败数)"
}
......@@ -550,7 +558,7 @@
"被取消的任务状态显示为 cancelled",
"关联的调用记录状态同步为 cancelled"
],
"changelog": {"id": "CHG-026", "date": "2026-06-25", "reason": "新增批量取消异步任务功能"}
"changelog": {"id": "CHG-035", "date": "2026-07-03", "reason": "批量取消时同步调用 Celery Revoke 移除 Redis 队列消息"}
}
]
},
......@@ -563,7 +571,7 @@
"steps": [
{
"op": "OP-F-04.11.1",
"status": "notimpl",
"status": "done",
"tab": "admin",
"nav": [
"管理后台",
......@@ -573,37 +581,47 @@
"actions": [
"登录管理后台",
"进入「模型调用与任务记录」模块",
"(可选)在筛选栏中选择业务编码/状态/提交时间范围",
"点击「取消全部」按钮",
"在确认弹框中点击「确认取消全部」"
"在确认弹框中点击「确认取消全部」(确认文案会根据是否有筛选条件显示「当前筛选条件下的」或「所有」)"
],
"backend": [
{
"tag": "receive",
"text": "接收 POST /api/v1/async-tasks/cancel-all 请求"
"text": "接收 POST /api/v1/async-tasks/cancel-all 请求(携带可选筛选参数:status/biz_type/task_id/start_time/end_time)"
},
{
"tag": "validate",
"text": "验证筛选参数"
},
{
"tag": "query",
"text": "按筛选条件分批查询 async_tasks:JOIN call_records 获取 biz_type,支持 biz_type/status/task_id/submitted_at 多维筛选,每批 100 条,循环取消直至全部处理完毕"
},
{
"tag": "write",
"text": "分批查询 async_tasks 表:WHERE status IN (pending,processing),每批 100 条,循环取消直至全部处理完毕"
"text": "逐批更新 async_tasks:status=cancelled(批量 UPDATE,一次 SQL 处理一批)"
},
{
"tag": "write",
"text": "逐批更新 async_tasks:status=cancelled"
"text": "逐批更新关联 call_records:status=cancelled(批量 UPDATE,一次 SQL 处理一批)"
},
{
"tag": "write",
"text": "逐批更新关联 call_records:status=cancelled"
"text": "逐批调用 celery_app.control.revoke(celery_task_id_list, terminate=False) 从 Redis 队列批量移除消息"
},
{
"tag": "return",
"text": "返回取消结果统计(total/成功/失败数)"
"text": "返回取消结果统计(total/batch_count)"
}
],
"expected": [
"页面提示「取消全部成功,共取消 N 个任务」",
"所有 pending/processing 任务状态显示为 cancelled",
"关联的调用记录状态同步为 cancelled"
"页面提示「取消成功,共取消 N 个任务」",
"所有符合条件的 pending/processing 任务状态显示为 cancelled",
"关联的调用记录状态同步为 cancelled",
"已取消的任务不再被 Worker 消费执行"
],
"changelog": {"id": "CHG-026", "date": "2026-06-25", "reason": "新增取消全部异步任务功能"}
"changelog": {"id": "CHG-035", "date": "2026-07-03", "reason": "取消全部支持筛选条件 + 同步调用 Celery Revoke 移除 Redis 队列消息"}
}
]
}
......@@ -639,6 +657,7 @@
{"date": "2026-06-25", "id": "CHG-029", "type": "modify", "title": "CHG-028 方案简化:去掉数据库字段,改为请求体复制按钮", "desc": "用户反馈不需要变量映射,只需复制最终请求体到 Apifox。OP-F-04.3.1 → notimpl。方案改为:去掉 input_variables 数据库字段,在请求体展示区域添加「复制」按钮即可。", "done": true},
{"date": "2026-06-25", "id": "CHG-030", "type": "modify", "title": "CHG-030 前端解析模板提取变量值", "desc": "前端从 template_info 模板内容中解析 {{xxx}} 占位符,与 request_body 中的实际文本匹配提取变量值,展示变量卡片并支持一键复制。OP-F-04.3.1 → done。", "done": false},
{"date": "2026-06-29", "id": "CHG-032", "type": "modify", "title": "调用记录和异步任务列表新增筛选功能", "desc": "OP-F-04.4.1 / OP-F-04.8.1 → notimpl。调用记录列表新增业务编码/状态/账号/模型/时间范围筛选。异步任务列表新增状态筛选和提交时间范围筛选。", "done": true},
{"date": "2026-06-30", "id": "CHG-034", "type": "modify", "title": "异步任务列表新增业务编码筛选", "desc": "OP-F-04.8.1 → done。异步任务列表新增业务编码筛选控件。GET /api/v1/async-tasks 新增 biz_type 查询参数(联表 call_records)。前端异步任务筛选栏新增业务编码 Select 下拉框。", "done": true}
{"date": "2026-06-30", "id": "CHG-034", "type": "modify", "title": "异步任务列表新增业务编码筛选", "desc": "OP-F-04.8.1 → done。异步任务列表新增业务编码筛选控件。GET /api/v1/async-tasks 新增 biz_type 查询参数(联表 call_records)。前端异步任务筛选栏新增业务编码 Select 下拉框。", "done": true},
{"date": "2026-07-03", "id": "CHG-035", "type": "modify", "title": "取消任务时同步调用 Celery Revoke 移除 Redis 队列消息", "desc": "OP-F-04.9.1 / OP-F-04.10.1 / OP-F-04.11.1 → done。取消单个/批量/全部异步任务时,在更新 DB 状态后同步调用 celery_app.control.revoke() 从 Redis 队列移除消息。取消全部接口新增筛选参数支持。", "done": true}
]
}
\ No newline at end of file
......@@ -193,7 +193,7 @@
"method": "POST",
"path": "/api/v1/async-tasks/:task_id/cancel",
"name": "取消异步任务",
"description": "取消正在执行的异步任务,同步更新关联调用记录状态为 cancelled",
"description": "取消正在执行的异步任务,同步更新关联调用记录状态为 cancelled。同时调用 Celery revoke 从 Redis 队列移除消息。",
"params": [
{"name": "task_id", "in": "path", "type": "string", "required": true, "desc": "任务 ID"}
],
......@@ -207,6 +207,7 @@
{"tag": "validate", "text": "验证任务存在且状态为 pending/processing"},
{"tag": "write", "text": "更新 async_tasks 表 status=cancelled"},
{"tag": "write", "text": "更新关联 call_records 表 status=cancelled"},
{"tag": "write", "text": "调用 celery_app.control.revoke(celery_task_id, terminate=False) 从 Redis 队列移除消息"},
{"tag": "return", "text": "返回操作结果"}
]
},
......@@ -214,7 +215,7 @@
"method": "POST",
"path": "/api/v1/async-tasks/batch-cancel",
"name": "批量取消异步任务",
"description": "批量取消多个异步任务,同步更新关联调用记录。支持任意数量任务,内部分批处理(每批 100 条)。",
"description": "批量取消多个异步任务,同步更新关联调用记录。取消时同步调用 Celery revoke 从 Redis 队列移除消息。支持任意数量任务,内部分批处理(每批 100 条)。",
"params": [
{"name": "task_ids", "in": "body", "type": "array", "required": true, "desc": "待取消的任务 ID 数组"}
],
......@@ -228,6 +229,7 @@
{"tag": "write", "text": "分批查询 async_tasks 表 WHERE id IN (:ids) AND status IN (pending,processing),每批 100 条"},
{"tag": "write", "text": "逐批更新 async_tasks:status=cancelled"},
{"tag": "write", "text": "逐批更新关联 call_records:status=cancelled"},
{"tag": "write", "text": "逐批调用 celery_app.control.revoke(celery_task_id, terminate=False) 从 Redis 队列移除消息"},
{"tag": "return", "text": "返回取消结果统计(total/success_count/failed_count/failed_ids)"}
]
},
......@@ -235,17 +237,25 @@
"method": "POST",
"path": "/api/v1/async-tasks/cancel-all",
"name": "取消全部异步任务",
"description": "取消当前所有 pending/processing 状态的异步任务,同步更新关联调用记录。内部分批处理(每批 100 条),循环直至全部处理完毕。",
"params": [],
"description": "取消当前所有 pending/processing 状态的异步任务,同步更新关联调用记录。支持按状态/业务编码/任务ID/时间范围筛选条件取消(不传筛选条件时取消全部 pending/processing 任务)。内部分批处理(每批 100 条),循环直至全部处理完毕。取消时同步调用 Celery revoke 从 Redis 队列移除消息。",
"params": [
{"name": "status", "in": "query", "type": "string", "required": false, "desc": "按状态筛选,不传则取消所有 pending/processing"},
{"name": "biz_type", "in": "query", "type": "string", "required": false, "desc": "按业务编码筛选"},
{"name": "task_id", "in": "query", "type": "string", "required": false, "desc": "按 celery_task_id 模糊搜索"},
{"name": "start_time", "in": "query", "type": "string", "required": false, "desc": "筛选 submitted_at >= start_time"},
{"name": "end_time", "in": "query", "type": "string", "required": false, "desc": "筛选 submitted_at <= end_time"}
],
"responses": [
{"code": 200, "desc": "取消成功", "schema": "{total: integer, batch_count: integer}"},
{"code": 400, "desc": "无待取消任务", "schema": ""}
],
"backend": [
{"tag": "receive", "text": "接收 POST /api/v1/async-tasks/cancel-all 请求"},
{"tag": "query", "text": "分批查询 async_tasks:WHERE status IN (pending,processing),每批 100 条"},
{"tag": "validate", "text": "验证筛选参数"},
{"tag": "query", "text": "按筛选条件分批查询 async_tasks:JOIN call_records 获取 biz_type,支持 biz_type/status/task_id/submitted_at 多维筛选,每批 100 条"},
{"tag": "write", "text": "逐批更新 async_tasks:status=cancelled"},
{"tag": "write", "text": "逐批更新关联 call_records:status=cancelled"},
{"tag": "write", "text": "逐批调用 celery_app.control.revoke(celery_task_id, terminate=False) 从 Redis 队列移除消息"},
{"tag": "return", "text": "返回取消结果统计(total/batch_count)"}
]
}
......@@ -266,6 +276,7 @@
{"date": "2026-06-25", "id": "CHG-029", "type": "modify", "title": "CHG-028 方案简化", "desc": "去掉 input_variables 参数设计,不需要后端字段变更。前端直接复制已有 request_body。", "done": true},
{"date": "2026-06-29", "id": "CHG-031", "type": "modify", "title": "by-template 创建调用记录时 biz_type 自动设为模板业务编码", "desc": "POST /api/v1/calls 的 biz_type 参数在 by-template 场景下由系统自动填充为模板 code,无需业务侧手动传入。POST /api/v1/calls 接口 biz_type 参数行为不变。", "done": true},
{"date": "2026-06-29", "id": "CHG-032", "type": "modify", "title": "调用记录和异步任务列表新增筛选功能", "desc": "GET /api/v1/calls 新增 account_name/start_time/end_time 查询参数。GET /api/v1/async-tasks 新增 start_time/end_time 查询参数。前端新增筛选栏。", "done": true},
{"date": "2026-06-30", "id": "CHG-034", "type": "modify", "title": "异步任务列表新增业务编码筛选", "desc": "GET /api/v1/async-tasks 新增 biz_type 查询参数(JOIN call_records 表按 biz_type 精确匹配筛选)。前端异步任务筛选栏新增业务编码 Select 下拉框。", "done": true}
{"date": "2026-06-30", "id": "CHG-034", "type": "modify", "title": "异步任务列表新增业务编码筛选", "desc": "GET /api/v1/async-tasks 新增 biz_type 查询参数(JOIN call_records 表按 biz_type 精确匹配筛选)。前端异步任务筛选栏新增业务编码 Select 下拉框。", "done": true},
{"date": "2026-07-03", "id": "CHG-035", "type": "modify", "title": "取消任务时同步调用 Celery Revoke 移除 Redis 队列消息", "desc": "取消单个/批量/全部异步任务时,在更新 DB 状态后同步调用 celery_app.control.revoke(celery_task_id, terminate=False) 从 Redis 队列移除消息,避免已取消的任务仍被 Worker 消费。POST /api/v1/async-tasks/cancel-all 新增 status/biz_type/task_id/start_time/end_time 筛选参数。", "done": true}
]
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!