Tasks

A task is one execution of one tool — the smallest unit of work in VTK. Tasks belong to a job; files written by one task are visible to the next under the job’s working directory. See Concepts for the surrounding model.

A task in a job submission consists of a tool identifier, its parameters, and optionally a tool version:

{
    "tool": "<tool>",
    "parameters": {
        "<param1>": "<value1>",
        "<param2>": "<value2>"
    },
    "version": "<optional-tool-version>"
}

If version is omitted, the tool version pinned for your organization is used, or the latest available version. A complete list of available tools and their parameters is in the Tools section.

Tasks API

All task endpoints live underneath their parent job at https://api.vtk.castlabs.com.

List tasks of a job

GET /o/{organization_urn}/jobs/{job_id}/tasks

Permission: vtk:ListTasks on arn:vtk:api::{organization_urn}:jobs/{job_id}/tasks

Query parameters: limit, offset, status, tool (filter by tool name).

curl https://api.vtk.castlabs.com/o/urn:janus:organization:acme/jobs/abcDEFGHIjk/tasks \
  -H 'Authorization: Bearer <token>' \
  -H 'x-castlabs-organization: urn:janus:organization:acme'

Get task details

GET /o/{organization_urn}/jobs/{job_id}/tasks/{task_id}

Permission: vtk:GetTask on arn:vtk:api::{organization_urn}:jobs/{job_id}/tasks/{task_id}

Returns the resolved task: tool identifier, resolved version, status, and parameters.

Get task logs

GET /o/{organization_urn}/jobs/{job_id}/tasks/{task_id}/log

Permission: vtk:GetTaskLog on arn:vtk:api::{organization_urn}:jobs/{job_id}/tasks/{task_id}/log

Returns the log messages produced by the task during execution.

curl https://api.vtk.castlabs.com/o/urn:janus:organization:acme/jobs/abcDEFGHIjk/tasks/12345/log \
  -H 'Authorization: Bearer <token>' \
  -H 'x-castlabs-organization: urn:janus:organization:acme'

Response:

{
  "count": 2,
  "results": [
    { "timestamp": 1607374149000, "message": "Running tool..." },
    { "timestamp": 1607374152000, "message": "Done." }
  ]
}

Timestamps are Unix milliseconds.

Parallel task execution

Usually steps in the execution of a job depend on the previous step and are executed sequentially by default — for example:

  • the 2nd pass of an H.264 encoding is dependent on the 1st pass

  • the processing of a file depends on the download to be completed

But some steps don’t depend on each other and can be executed in parallel:

  • the download of a file from source S2 does not depend on the successful download of a file from S1

  • no H.264 2nd pass depends on the result of another 2nd pass

By adding |p to a tool name the execution engine treats that tool as not depending on the result of the previous tool.

[
    { "tool": "do:something" },
    { "tool": "do:something_else_in_parallel|p" }
]

A concrete example — two storage:get tasks fetching from different buckets at the same time:

{
    "tasks": [
        { "tool": "storage:get",
          "parameters": {
              "location": "s3://{acme-aws-access-keys}@acme-bucket-a/in/",
              "files": ["video.mp4"]
          } },
        { "tool": "storage:get|p",
          "parameters": {
              "location": "s3://{acme-aws-access-keys}@acme-bucket-b/in/",
              "files": ["audio.mp4"]
          } }
    ]
}

Chaining tasks into one slot: |c

|p says “does not depend on the previous tool”. |c says the opposite, and adds something: this tool depends on the previous one and runs in the same execution slot, directly after it, on the same machine.

[
    { "tool": "shaka:package_cmaf" },
    { "tool": "storage:put|c" }
]

Without |c these are two stages: everything in the packaging stage has to finish before any upload starts, the upload is dispatched as its own task, and it may land on a different machine — which means reading the packaged files back through the shared filesystem. With |c the upload runs as the second step of the packaging task: no second container start, no queue round trip, no stage barrier, and it reads the files the previous step just wrote locally.

Chains combine with |p, which is where they earn the most. One slot per chunk, upload included, all in one stage:

[
    { "tool": "storage:get" },
    { "tool": "ffmpeg:cmd" },
    { "tool": "storage:put|c" },
    { "tool": "ffmpeg:cmd|p" },
    { "tool": "storage:put|c" },
    { "tool": "ffmpeg:cmd|p" },
    { "tool": "storage:put|c" }
]

Each chunk’s upload overlaps the other chunks’ encoding instead of waiting for the slowest one.

What to keep in mind:

  • Each step stays its own task — own log stream, own start/end times, own usage rows. The job detail page shows them exactly as before.

  • A chain fails at its first failing step. The steps after it do not run, and the error names the step that failed.

  • A chain is retried as a whole. If a step hits an infrastructure error, or the machine is reclaimed (spot), the chain restarts from its first step on another machine — including steps that had already finished. Chain steps that are expensive and not idempotent are better left as separate tasks.

  • The slot is held for the whole chain. A chain of encode + upload occupies its 2 vCPU while the upload runs, so chaining a long I/O-bound step onto a CPU-bound one trades a little capacity for the removed barrier.

  • |c on the first task of a job has nothing to attach to and is treated as a plain task.

Local scratch space: /job/local

/job is the job’s shared workdir: every task of the job sees it, on any machine, and it is where results for later stages go. Each slot (one task, or one whole |c chain) on the SFN pools (region: sfn:*) also gets a private directory at /job/local on the machine’s local disk:

  • Fast and local. It isn’t on the shared filesystem, so writing and reading it back never goes over the network. It is the place for intermediates a chain passes from one step to the next.

  • Scratch only. It starts empty and is deleted when the slot ends, whatever the outcome. A chain that is retried starts again with an empty /job/local.

  • Not shared. Other slots never see it: not the parallel |p branches of the same job, not later stages, not other jobs. Anything a later stage needs must be written to /job.

  • Large, not reserved. All slots on a machine share its 500 GB local disk (with the machine’s read cache), and there is no per-slot limit. If a step fails while that disk is full, the task is not failed: it is returned to the queue and restarts from its first step on another machine, and its log says so. A task that doesn’t fit anywhere fails after a few such attempts.

[
    { "tool": "utils:write_text",
      "parameters": { "base64value": "aW50ZXJtZWRpYXRlCg==", "outputfile": "local/intermediate.txt" } },
    { "tool": "utils:copy|c",
      "parameters": { "pattern": "^local/intermediate.txt$", "to": "out/final.txt" } }
]

local/intermediate.txt never reaches the shared filesystem; out/final.txt does, and outlives the slot. Tool paths are relative to /job, so local/… is /job/local/…. On the classic pools, local/ is an ordinary subdirectory of /job.

Previous topic: Status