Skip to content

Tasks API

Base path: /api/v1/tasks

Overview

The Tasks API manages background processing jobs: search, dedup, crawl, OCR, index, keyword expansion. Tasks are created by pipelines and other services; this API provides listing, detail retrieval, and cancellation.

Endpoints

MethodPathDescription
GET/tasksList tasks
GET/tasks/{id}Get task detail
POST/tasks/{id}/cancelCancel a running task

GET /api/v1/tasks

Description: List tasks with optional filters. Results are ordered by created_at descending.

Query Parameters

ParameterTypeRequiredDescription
project_idintNoFilter by project ID
statusstringNoFilter by status: pending, running, completed, failed, cancelled
limitintNoMax results (default: 50)

Response: ApiResponse[list[TaskSchema]]

TaskSchema (list view)

FieldTypeDescription
idintTask ID
project_idintProject ID
task_typestringsearch, dedup, crawl, ocr, index, keyword_expand
statusstringpending, running, completed, failed, cancelled
progressintCurrent progress
totalintTotal steps
created_atstringISO 8601 datetime

List Example

bash
curl -X GET "http://localhost:8000/api/v1/tasks?project_id=1&status=running&limit=20"
json
{
  "code": 200,
  "message": "success",
  "data": [
    {
      "id": 42,
      "project_id": 1,
      "task_type": "search",
      "status": "running",
      "progress": 30,
      "total": 100,
      "created_at": "2025-03-12T10:00:00"
    }
  ]
}

GET /api/v1/tasks/

Description: Get full task detail including params, result, and error message.

Path Parameters

ParameterTypeDescription
idintTask ID

Response: ApiResponse[TaskDetailSchema]

TaskDetailSchema

FieldTypeDescription
idintTask ID
project_idintProject ID
task_typestringTask type
statusstringTask status
progressintCurrent progress
totalintTotal steps
paramsobjectInput parameters
resultobjectOutput result (when completed)
error_messagestringError message (when failed)
created_atstringISO 8601 datetime
started_atstringISO 8601 datetime (nullable)
completed_atstringISO 8601 datetime (nullable)

Detail Example

bash
curl -X GET "http://localhost:8000/api/v1/tasks/42"
json
{
  "code": 200,
  "message": "success",
  "data": {
    "id": 42,
    "project_id": 1,
    "task_type": "search",
    "status": "completed",
    "progress": 100,
    "total": 100,
    "params": {"query": "machine learning", "sources": ["semantic_scholar"]},
    "result": {"papers_found": 15, "imported": 10},
    "error_message": "",
    "created_at": "2025-03-12T10:00:00",
    "started_at": "2025-03-12T10:00:01",
    "completed_at": "2025-03-12T10:02:30"
  }
}

POST /api/v1/tasks/{id}/cancel

Description: Cancel a running or pending task. Tasks in completed, failed, or cancelled state cannot be cancelled.

Path Parameters

ParameterTypeDescription
idintTask ID

Response: ApiResponse (no data)

Cancel Example

bash
curl -X POST "http://localhost:8000/api/v1/tasks/42/cancel"
json
{
  "code": 200,
  "message": "Task cancelled",
  "data": null
}

Error Codes

CodeDescription
200Success
400Cannot cancel task (already completed/failed/cancelled)
404Task not found

Released under the MIT License.