Tasks are the core execution units in Compose. A task is a durable workflow that can execute its own logic as well as trigger other tasks. Tasks run in a sandboxed environment and cannot access the file system, network, blockchains, etc, without communicating outside of the sandbox by calling Context Functions. This allows all task functionality to be fully auditable and verifiable. Each task is a TypeScript module that exports aDocumentation Index
Fetch the complete documentation index at: https://docs.goldsky.com/llms.txt
Use this file to discover all available pages before exploring further.
main function with access to context functions for durable operations.
The main function receives the injected context as its first argument and the payload sent by the trigger as its second argument.
Types for context functions are stored in the local .compose/ folder and can be referenced from your task files like so:
Task Structure
Every task must export amain function with this signature:
main function. If none is found, the task fails to load. Default exports, run, and lifecycle hooks like onStart / onShutdown are not supported — main is the single entrypoint.
Task Triggers
Tasks are invoked by “triggers” — see Task Triggers for details. The supported trigger types are:- Cron — called on a schedule expressed as a cron expression, with no payload.
- HTTP — called by your application or CLI with various auth options. The request body is passed as the payload.
- Onchain — triggered by onchain events, called with a raw log payload decodable via Contract classes.
Task-Level Retry Configuration
Configure retries in your app manifest:- Task Failure: If the task throws an error, the durable execution engine marks the attempt as failed.
- Retry Delay: Waits
initial_interval_msbefore the first retry. - Exponential Backoff: Each subsequent retry interval is the previous one multiplied by
backoff_factor. - Retry Sequence (for the example above): delays of 2000ms → 3000ms → 4500ms → 6750ms between the 5 attempts.
- Final Failure: After
max_attemptsattempts, the task is permanently failed. - Default Behavior: When
retry_configis omitted, tasks run withmax_attempts: 1— i.e. no retries.
Task Context
A task’smain() function is invoked with a context object — see Context for full details. Here’s a brief overview of what context enables:
- State management — Collections
- Blockchain interactions — evm
- HTTP requests — fetch
- Task-to-task execution — callTask
- Reading env variables — env
Next Steps
Context
Get detailed API docs for all available context functions for HTTP, blockchain, and database operations.
Task Triggering
Learn how to trigger tasks and query your application via HTTP API.