端点: DELETE /api/v0/data_pipeline/tasks
功能: 删除任务目录,支持单个和批量删除
主要用途: 清理不需要的任务目录以节省存储空间,同时保留任务记录用于历史查询
curl -X DELETE \
http://localhost:8084/api/v0/data_pipeline/tasks \
-H "Content-Type: application/json" \
-d '{
"task_ids": ["task_20250702_223802"],
"confirm": true
}'
curl -X DELETE \
http://localhost:8084/api/v0/data_pipeline/tasks \
-H "Content-Type: application/json" \
-d '{
"task_ids": ["task_20250702_223802", "task_20250702_223751", "task_20250702_223705"],
"confirm": true,
"delete_database_records": false,
"continue_on_error": true
}'
import requests
import json
# 删除单个任务(只删除目录,保留数据库记录)
def delete_single_task(task_id):
payload = {
"task_ids": [task_id],
"confirm": True,
"delete_database_records": False
}
response = requests.delete(
'http://localhost:8084/api/v0/data_pipeline/tasks',
json=payload
)
return response.json()
# 批量删除任务
def delete_multiple_tasks(task_ids):
payload = {
"task_ids": task_ids,
"confirm": True,
"delete_database_records": False,
"continue_on_error": True
}
response = requests.delete(
'http://localhost:8084/api/v0/data_pipeline/tasks',
json=payload
)
return response.json()
# 使用示例
result = delete_single_task("task_20250702_223802")
print(json.dumps(result, indent=2, ensure_ascii=False))
参数名 | 类型 | 必需 | 默认值 | 说明 |
---|---|---|---|---|
task_ids |
Array[String] | ✅ | - | 要删除的任务ID列表,支持单个或多个 |
confirm |
Boolean | ✅ | - | 确认删除操作,必须为 true |
delete_database_records |
Boolean | ❌ | false |
是否删除数据库记录 |
continue_on_error |
Boolean | ❌ | true |
批量删除时遇到错误是否继续 |
task_ids
(必需)["task_20250702_223802"]
["task_20250702_223802", "task_20250702_223751"]
confirm
(必需)true
true
,将返回400错误delete_database_records
(可选)false
false
: 只删除目录,保留任务记录(推荐)true
: 同时删除目录和数据库记录false
,保留历史记录continue_on_error
(可选)true
true
: 遇到错误继续删除其他任务false
: 遇到第一个错误就停止{
"success": true,
"code": 200,
"message": "任务目录删除成功",
"data": {
"deleted_at": "2025-07-02T22:57:21.317708",
"deleted_tasks": [
{
"success": true,
"task_id": "task_20250702_223802",
"directory_deleted": true,
"database_records_deleted": false,
"deleted_files_count": 15,
"deleted_size": "2.5 MB",
"deleted_at": "2025-07-02T22:57:21.317708"
}
],
"failed_tasks": [],
"summary": {
"total_requested": 1,
"successfully_deleted": 1,
"failed": 0
}
}
}
{
"success": true,
"code": 200,
"message": "批量删除部分完成",
"data": {
"deleted_at": "2025-07-02T22:57:21.317708",
"deleted_tasks": [
{
"success": true,
"task_id": "task_20250702_223802",
"directory_deleted": true,
"database_records_deleted": false,
"deleted_files_count": 15,
"deleted_size": "2.5 MB",
"deleted_at": "2025-07-02T22:57:21.317708"
}
],
"failed_tasks": [
{
"task_id": "task_20250702_invalid",
"error": "任务目录不存在",
"error_code": "DELETE_FAILED"
}
],
"summary": {
"total_requested": 2,
"successfully_deleted": 1,
"failed": 1
}
}
}
{
"success": false,
"code": 400,
"message": "缺少必需参数: confirm",
"missing_params": ["confirm"]
}
{
"success": false,
"code": 400,
"message": "task_ids必须是非空的任务ID列表"
}
{
"success": false,
"code": 500,
"message": "删除任务失败,请稍后重试"
}
字段名 | 类型 | 说明 |
---|---|---|
success |
Boolean | 该任务是否删除成功 |
task_id |
String | 任务ID |
directory_deleted |
Boolean | 目录是否被删除 |
database_records_deleted |
Boolean | 数据库记录是否被删除 |
deleted_files_count |
Integer | 删除的文件数量 |
deleted_size |
String | 删除的文件总大小(格式化) |
deleted_at |
String | 删除时间(ISO格式) |
字段名 | 类型 | 说明 |
---|---|---|
total_requested |
Integer | 请求删除的任务总数 |
successfully_deleted |
Integer | 成功删除的任务数 |
failed |
Integer | 删除失败的任务数 |
delete_database_records: false
)data_pipeline_tasks.directory_exists = false
data_pipeline_tasks.updated_at = 当前时间
delete_database_records: true
)data_pipeline_tasks
表中的任务记录data_pipeline_task_steps
表中的步骤记录删除后可以通过任务列表API查看效果:
curl http://localhost:8084/api/v0/data_pipeline/tasks?limit=5
响应中会显示:
{
"tasks": [
{
"task_id": "task_20250702_223802",
"directory_exists": false,
"updated_at": "2025-07-02T22:57:21.550474",
...
}
]
}
confirm: true
参数delete_database_records: false
,保留历史记录continue_on_error
控制curl -X DELETE \
http://localhost:8084/api/v0/data_pipeline/tasks \
-H "Content-Type: application/json" \
-d '{
"task_ids": ["task_20250702_test1", "task_20250702_test2"],
"confirm": true
}'
curl -X DELETE \
http://localhost:8084/api/v0/data_pipeline/tasks \
-H "Content-Type: application/json" \
-d '{
"task_ids": ["task_20250702_failed"],
"confirm": true,
"delete_database_records": true
}'
import requests
from datetime import datetime, timedelta
def cleanup_old_tasks(days_old=30):
# 先获取任务列表
response = requests.get('http://localhost:8084/api/v0/data_pipeline/tasks?limit=100')
tasks = response.json()['data']['tasks']
# 筛选出旧任务
cutoff_date = datetime.now() - timedelta(days=days_old)
old_task_ids = []
for task in tasks:
if task.get('created_at'):
created_at = datetime.fromisoformat(task['created_at'].replace('Z', '+00:00'))
if created_at < cutoff_date:
old_task_ids.append(task['task_id'])
# 批量删除
if old_task_ids:
payload = {
"task_ids": old_task_ids,
"confirm": True,
"delete_database_records": False
}
response = requests.delete(
'http://localhost:8084/api/v0/data_pipeline/tasks',
json=payload
)
return response.json()
return {"message": "没有找到需要清理的旧任务"}