Skip to main content
A task is a discrete unit of work whose result can be checkpointed on its own. When an entrypoint or a Graph API node runs several operations, wrap each operation in a task instead of putting all the work in one function body. With a checkpointer, completed task results are saved, so a resumed thread can skip finished work and continue from the next task. This page covers retries, timeouts, caching, and error recovery on tasks. For concepts, see the Functional API overview. For an ordered build path, see the Build checklist for the Functional API. For the shared retry and timeout lifecycle, see Fault tolerance.

Add a retry policy

Pass retry_policy on @task. The default RetryPolicy retries selected network and HTTP 5xx errors. It does not retry ValueError. This example retries ValueError.

Set a timeout

Cap how long a single async attempt can run. If a retry policy retries the timeout error, the timer resets on the next attempt. Pass timeout on @task or @entrypoint in seconds or as a datetime.timedelta. Timeouts apply only to async tasks and entrypoints. Setting timeout on a sync function raises an error at declaration. The first attempt sleeps past the timeout and raises NodeTimeoutError, which subclasses TimeoutError. The retry policy retries that error. The second attempt returns immediately.

Cache a task

Cache a task result by input. Pass a cache on the entrypoint and a policy on the task. ttl is in seconds. The second call is a cache hit, so this run takes about 1 second, not 2.

Resume after an error

A checkpointer is required so completed task results survive the failed run. slow_task is restored from the checkpoint. get_info runs again and returns "OK". The entrypoint still returns the slow_task result. Resume the same thread_id with None.

See also