Error Detection and Handling
Moose provides multiple layers of error protection, both at the workflow and task level:
Workflow-Level Retries and Timeouts
Moose automatically catches any runtime errors during workflow execution. Errors are logged for debugging, and the orchestrator will retry failed tasks according to the retries option.
In your Workflow, you can configure the following options to control workflow behavior, including timeouts and retries:
import { Task, Workflow } from "@514labs/moose-lib"; export const myworkflow = new Workflow("myworkflow", { startingTask: task1, retries: 1, timeout: "10m",});Task-Level Errors and Retries
For more granular control over task-level errors and retries, you can configure your individual tasks to have their own retry behavior.
For workflows & tasks that may not have a predefined timeout, you may set never as the timeout.
import { Task, Workflow } from "@514labs/moose-lib"; export const task1 = new Task<Foo, void>("task1", { run: async (ctx) => {}, retries: 1, timeout: "5m"}); export const myworkflow = new Workflow("myworkflow", { startingTask: task1, retries: 2, timeout: "10m",});Example: Workflow and Task Retry Interplay
When configuring retries, it's important to understand how workflow-level and task-level retries interact. The retries value specifies the number of retry attempts after the initial execution fails.
Consider the following scenario:
- Workflow retries: 1 (1 initial + 1 retry = 2 total attempts)
- Task retries: 2 (1 initial + 2 retries = 3 total attempts)
import { Task, Workflow } from "@514labs/moose-lib"; export const task1 = new Task<Foo, void>("task1", { run: async (ctx) => {}, retries: 2,}); export const myworkflow = new Workflow("myworkflow", { startingTask: task1, retries: 1,});If the task keeps failing, the retry sequence would proceed as follows:
-
Workflow Attempt 1
- Task Attempt 1 (initial): Task fails
- Task Retry 1: Task fails
- Task Retry 2: Task fails
- Workflow attempt fails after exhausting task retries
-
Workflow Retry 1
- Task Attempt 1 (initial): Task fails
- Task Retry 1: Task fails
- Task Retry 2: Task fails
- Workflow fails after exhausting all retries
This results in up to 6 total task executions: 3 task attempts × 2 workflow attempts.