Skip to main content

Overview

The Tasks API manages the work task queue for asynchronous operations like pipeline execution, ML training, and digital twin updates. These endpoints require authentication when WORKER_AUTH_TOKEN is configured.

List Work Tasks

Returns the current queue length.
curl -X GET http://localhost:8080/api/worktasks \
  -H "Authorization: Bearer your-token"

Response

queue_length
number
Current number of tasks in the queue

Submit Work Task

Submits a new work task to the queue.
curl -X POST http://localhost:8080/api/worktasks \
  -H "Authorization: Bearer your-token" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "pipeline_execution",
    "priority": 1,
    "project_id": "proj-123",
    "task_spec": {
      "pipeline_id": "pipe-456",
      "parameters": {}
    },
    "resource_requirements": {
      "cpu": "1",
      "memory": "2Gi",
      "gpu": false
    },
    "data_access": {
      "input_datasets": ["dataset-1"],
      "output_location": "s3://output/",
      "storage_credentials": "creds-secret"
    }
  }'

Request Body

type
string
required
Task type: pipeline_execution, ml_training, ml_inference, or digital_twin_update
priority
number
Task priority (higher = higher priority, defaults to 1)
project_id
string
required
Project ID
task_spec
object
required
Task-specific parameters
resource_requirements
object
required
Resource requirements
data_access
object
required
Data access configuration

Response

worktask_id
string
Work task ID
type
string
Task type
status
string
Current status: queued, scheduled, spawned, executing, completed, failed, timeout, or cancelled
priority
number
Task priority
submitted_at
string
ISO 8601 timestamp
started_at
string
ISO 8601 timestamp (if started)
completed_at
string
ISO 8601 timestamp (if completed)
project_id
string
Project ID
task_spec
object
Task-specific parameters
resource_requirements
object
Resource requirements
data_access
object
Data access configuration
error_message
string
Error message (if failed)
kubernetes_job_name
string
Kubernetes job name (if spawned)
cluster_name
string
Cluster task was dispatched to
retry_count
number
Number of retry attempts
max_retries
number
Maximum retry attempts
retry_reason
string
Reason for retry

Get Work Task

Returns a single work task by ID.
curl -X GET http://localhost:8080/api/worktasks/task-123 \
  -H "Authorization: Bearer your-token"

Path Parameters

id
string
required
Work task ID

Response

Returns the work task object (see Submit Work Task for schema).

Update Work Task Status

Updates the status of a work task. Called by worker jobs to report progress.
curl -X POST http://localhost:8080/api/worktasks/task-123 \
  -H "Authorization: Bearer your-token" \
  -H "Content-Type: application/json" \
  -d '{
    "worktask_id": "task-123",
    "status": "completed",
    "output_location": "s3://output/result.json",
    "metadata": {
      "records_processed": 1000
    }
  }'

Path Parameters

id
string
required
Work task ID

Request Body

worktask_id
string
required
Work task ID (must match path parameter)
status
string
required
New status: executing, completed, failed, timeout, or cancelled
output_location
string
Output location (for completed tasks)
metadata
object
Additional metadata
error_message
string
Error message (for failed tasks)

Response

{
  "status": "updated"
}
Or for retryable errors:
{
  "status": "requeued_for_retry"
}

Automatic Retry

The system automatically retries tasks with transient errors (OOMKilled, Evicted, DeadlineExceeded). Tasks are requeued with incremented retry count up to the maximum retry limit.

Get Metrics

Returns queue and task metrics.
curl -X GET http://localhost:8080/api/metrics

Response

queue
object
Queue metrics
tasks_by_status
object
Task counts grouped by status
tasks_by_type
object
Task counts grouped by type
timestamp
string
ISO 8601 timestamp of metrics snapshot

WebSocket Updates

Subscribe to real-time task updates via WebSocket:
const ws = new WebSocket('ws://localhost:8080/ws/tasks');

ws.onmessage = (event) => {
  const message = JSON.parse(event.data);
  console.log('Task update:', message);
};

Message Format

{
  "event": "task_update",
  "task": {
    "worktask_id": "task-123",
    "status": "completed",
    "completed_at": "2024-01-15T10:35:00Z"
  }
}

Build docs developers (and LLMs) love