Demonstrates every retry mechanism and error handling pattern available in the Durable Task SDK.
| Feature | API |
|---|---|
| Declarative retry | RetryPolicy with exponential backoff |
| Failure predicate | RetryPolicy.handleFailure |
| Custom retry handler | AsyncRetryHandler with custom delays |
| Sub-orchestration retry | callSubOrchestrator with retry options |
| Error inspection | state.raiseIfFailed(), state.failureDetails |
- Node.js ≥ 22
- Docker (for the DTS Emulator)
cd examples/azure-managed
docker compose up -d
cp .env.emulator .env
cd ../..
npm install && npm run buildnpm run example -- ./examples/azure-managed/retry-and-error-handling/index.ts=== 1. RetryPolicy (exponential backoff) ===
Status: COMPLETED
Result: "Success on attempt 3 for \"retry-policy-...\""
=== 2. handleFailure Predicate ===
Status: COMPLETED
Result: "Success on attempt 3 for \"handle-failure-...\""
=== 3. Custom AsyncRetryHandler ===
Status: COMPLETED
Result: "Success on attempt 3 for \"custom-handler-...\""
=== 4. Sub-orchestration Retry ===
Status: COMPLETED
Result: {"sum":15}
=== 5. Error Handling (raiseIfFailed) ===
Status: FAILED
raiseIfFailed() threw: OrchestrationFailedError — ...
Failure type: Error
Failure message: FatalError: This operation cannot succeed
=== All retry/error demos completed successfully! ===
npm run example -- ./examples/azure-managed/retry-and-error-handling/index.ts 2>&1 | grep "All retry/error demos completed successfully"To run this sample against a real Azure Managed Durable Task Scheduler instead of the local emulator:
-
Create a scheduler and task hub (if you haven't already) — see the parent README for
az durabletaskcommands. -
Configure
.envfor your cloud endpoint:cd examples/azure-managed cp .env.example .env # Edit .env with your scheduler endpoint and task hub name
Example
.env:DURABLE_TASK_SCHEDULER_CONNECTION_STRING=Endpoint=https://your-scheduler.eastus.durabletask.io;Authentication=DefaultAzure;TaskHub=your-taskhub
-
Authenticate with Azure:
az login
-
Run (no Docker needed):
npm run example -- ./examples/azure-managed/retry-and-error-handling/index.ts