{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/oec-sh/json-schema/oec-sh-task-response-schema.json",
  "title": "TaskResponse",
  "description": "Response schema for a single task.",
  "x-generated": "2026-11-19",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/_original/oec-sh-api-openapi.json#/components/schemas/TaskResponse",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "title": "Id",
      "description": "Unique task identifier"
    },
    "task_type": {
      "$ref": "#/$defs/TaskType",
      "description": "Type of task"
    },
    "status": {
      "$ref": "#/$defs/TaskStatus",
      "description": "Current task status"
    },
    "environment_id": {
      "anyOf": [
        {
          "type": "string",
          "format": "uuid"
        },
        {
          "type": "null"
        }
      ],
      "title": "Environment Id",
      "description": "Environment ID if applicable"
    },
    "environment_name": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Environment Name",
      "description": "Environment name (e.g. 'production')"
    },
    "project_name": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Project Name",
      "description": "Project name for this environment"
    },
    "organization_id": {
      "type": "string",
      "format": "uuid",
      "title": "Organization Id",
      "description": "Organization that owns this task"
    },
    "organization_name": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Organization Name",
      "description": "Organization display name"
    },
    "triggered_by": {
      "anyOf": [
        {
          "type": "string",
          "format": "uuid"
        },
        {
          "type": "null"
        }
      ],
      "title": "Triggered By",
      "description": "User who triggered this task (null for system-triggered tasks)"
    },
    "triggered_by_name": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Triggered By Name",
      "description": "Name or email of the user who triggered this task"
    },
    "server_id": {
      "anyOf": [
        {
          "type": "string",
          "format": "uuid"
        },
        {
          "type": "null"
        }
      ],
      "title": "Server Id",
      "description": "Server ID if applicable"
    },
    "server_name": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Server Name",
      "description": "Server display name"
    },
    "current_step": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Current Step",
      "description": "Current step being executed"
    },
    "progress_percent": {
      "type": "integer",
      "title": "Progress Percent",
      "description": "Overall progress percentage (0-100)",
      "default": 0
    },
    "steps_completed": {
      "type": "integer",
      "title": "Steps Completed",
      "description": "Number of steps completed",
      "default": 0
    },
    "total_steps": {
      "type": "integer",
      "title": "Total Steps",
      "description": "Total number of steps",
      "default": 1
    },
    "queued_at": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ],
      "title": "Queued At",
      "description": "When task was queued"
    },
    "started_at": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ],
      "title": "Started At",
      "description": "When task started executing"
    },
    "completed_at": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ],
      "title": "Completed At",
      "description": "When task completed (success or failure)"
    },
    "created_at": {
      "type": "string",
      "format": "date-time",
      "title": "Created At",
      "description": "When task was created"
    },
    "error_message": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Error Message",
      "description": "Error message if task failed"
    },
    "retry_count": {
      "type": "integer",
      "title": "Retry Count",
      "description": "Number of retry attempts made",
      "default": 0
    },
    "max_retries": {
      "type": "integer",
      "title": "Max Retries",
      "description": "Maximum retry attempts allowed",
      "default": 3
    },
    "duration_seconds": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Duration Seconds",
      "description": "Task duration in seconds (if completed)"
    },
    "is_terminal": {
      "type": "boolean",
      "title": "Is Terminal",
      "description": "Whether task is in terminal state (completed/failed/cancelled)",
      "default": false
    },
    "can_cancel": {
      "type": "boolean",
      "title": "Can Cancel",
      "description": "Whether task can be cancelled",
      "default": false
    },
    "arq_job_id": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Arq Job Id",
      "description": "ARQ job ID for worker tracking"
    },
    "message": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Message",
      "description": "Human-readable status message"
    },
    "error_traceback": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Error Traceback",
      "description": "Full error traceback if task failed"
    },
    "result": {
      "anyOf": [
        {
          "type": "object"
        },
        {
          "type": "null"
        }
      ],
      "title": "Result",
      "description": "Task result data if completed successfully"
    },
    "last_heartbeat": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ],
      "title": "Last Heartbeat",
      "description": "Last heartbeat timestamp from worker"
    },
    "heartbeat_enabled": {
      "type": "boolean",
      "title": "Heartbeat Enabled",
      "description": "Whether heartbeat monitoring is enabled",
      "default": true
    },
    "max_timeout_seconds": {
      "anyOf": [
        {
          "type": "integer"
        },
        {
          "type": "null"
        }
      ],
      "title": "Max Timeout Seconds",
      "description": "Custom timeout override for this task"
    }
  },
  "type": "object",
  "required": [
    "id",
    "task_type",
    "status",
    "organization_id",
    "created_at"
  ],
  "$defs": {
    "TaskStatus": {
      "type": "string",
      "enum": [
        "pending",
        "queued",
        "running",
        "completed",
        "failed",
        "cancelled",
        "retrying"
      ],
      "title": "TaskStatus",
      "description": "Task execution status."
    },
    "TaskType": {
      "type": "string",
      "enum": [
        "deploy",
        "redeploy",
        "clone",
        "destroy",
        "sync_status",
        "backup",
        "restore",
        "start",
        "stop",
        "restart",
        "pause",
        "resume",
        "module_deploy",
        "module_sync",
        "module_deploy_all"
      ],
      "title": "TaskType",
      "description": "Types of background tasks."
    }
  }
}