Skip to main content
Tasks are the core execution units in Compose. A task is a durable workflow that can execute it’s own logic as well as trigger other tasks. Tasks are run in a sandboxed environment and cannot access the file system, network, blockchains, etc, without communicating outside of the sandbox by executing Context Functions. This allows all task functionality to be fully auditable and verifiable. Each task is a TypeScript module with a main function that can access powerful context functions for durable operations. Each main function will be passed the injected context functions as well as the payload that was sent with the trigger. Types for context functions are stored in the local .compose/ folder and can be referenced from your task files like so:
import { TaskContext } from "compose";

Task Structure

Every task must export a main function with this signature:
import { TaskContext } from "compose";

export async function main(
  // injected by compose
  context: TaskContext,
  // update this with whatever payload your task will receive if your task supports http triggers
  // this will be undefined when your task is triggered with cron
  payload?: Record<string, unknown>
): Promise<unknown> {
  // Task implementation
}

Task Triggers

Tasks are invoked by “triggers”, see Task Triggers for details. Here’s the current types of supported triggers:
  • Cron - called with no arguments on a time interval expressed as a cron expression.
  • HTTP - called by your application or CLI with various auth options
  • Onchain - triggered by onchain events, called with a raw logs payload and decodable with Contract classes.

Task-Level Retry Configuration

Configure retries in your app manifest:
tasks:
  - name: "unreliable_task"
    path: "./tasks/flaky.ts"
    retry_config:
      max_attempts: 5
      initial_interval_ms: 2000
      backoff_factor: 1.5
How Task Retries Work:
  1. Task Failure: If the task throws an error, Our durable execution engine marks it as failed
  2. Retry Delay: Waits initial_interval_ms before first retry
  3. Exponential Backoff: Each retry interval is multiplied by backoff_factor
  4. Retry Sequence: 2000ms → 3000ms → 4500ms → 6750ms → 10125ms
  5. Final Failure: After 5 attempts, task is permanently failed
  6. Default Retry Configuration: By default tasks will be configured to not retry

Task Context

A task’s “main()” function will be injected with task context, see Context for more details. Here’s a brief overview of what context enables.

Next Steps