Task System API
异步任务系统,支持任务创建、状态追踪、放弃/重试和 webhook 通知。
Endpoints
| Endpoint | Method | Description |
|---|---|---|
/api/v1/task/create | POST | 创建任务 |
/api/v1/task/list | POST | 任务列表 |
/api/v1/task/detail | POST | 任务详情 |
/api/v1/task/cancel | POST | 放弃任务 |
/api/v1/task/retry | POST | 重试任务 |
/api/v1/task/execute | POST | 重新执行 |
/api/v1/task/logs | POST | 任务执行日志 |
/api/v1/task/test | POST | 沙盒测试 |
任务状态
pending → running → done
→ failed → retry → pending
→ cancelled
创建任务
POST /api/v1/task/create
{
"type": "waybill_loading_confirm",
"ref_id": "123456",
"webhook": {
"url": "https://example.com/webhook",
"events": ["done", "failed"],
"enabled": true
}
}
Response:
{
"code": 200,
"data": {
"id": "2JxQpF3K8vNqZrLmXwYbT4",
"status": "pending"
}
}
查询结果
POST /api/v1/task/detail
{ "id": "2JxQpF3K8vNqZrLmXwYbT4" }
接收通知
创建任务时配置 webhook,任务完成后自动回调:
{
"event": "task.done",
"task_id": "2JxQpF3K8vNqZrLmXwYbT4",
"type": "waybill_loading_confirm",
"ref_id": "123456",
"status": "done"
}
支持事件:done、failed、cancelled
放弃与重试
放弃:POST /api/v1/task/cancel
{ "id": "2JxQpF3K8vNqZrLmXwYbT4" }
重试(仅 failed):POST /api/v1/task/retry
{ "id": "2JxQpF3K8vNqZrLmXwYbT4" }
已支持的任务类型
| Task Type | 说明 |
|---|---|
pickup_confirm | 取件确认 |
waybill_confirm | 面单确认 |
waybill_loading_confirm | 装车确认 |