Step Execution Options
These settings are defined in your TypeScript flow code and compiled into SQL migrations. They control how individual steps are executed, delayed, and retried. Set defaults at the flow level, override for specific steps. Step-level options are null by default, inheriting from flow-level settings.
Default Configuration
Section titled “Default Configuration”new Flow({ slug: 'my_flow', maxAttempts: 3, // max retry attempts before marking as failed baseDelay: 1, // initial retry delay in seconds timeout: 60 // visibility timeout in seconds // Note: startDelay is step-level only, not available as a default at flow level})maxAttempts
Section titled “maxAttempts”Type: number
Default: 3
The maximum number of times a task will be attempted before being marked as permanently failed.
// Flow levelnew Flow({ slug: 'my_flow', maxAttempts: 5 })
// Step level (overrides flow default).step({ slug: 'my_step', maxAttempts: 7 }, handler)baseDelay
Section titled “baseDelay”Type: number
Default: 1
The initial delay (in seconds) before the first retry. pgflow uses exponential backoff, so subsequent retries will have increasingly longer delays.
// Flow levelnew Flow({ slug: 'my_flow', baseDelay: 2 })
// Step level (overrides flow default).step({ slug: 'my_step', baseDelay: 10 }, handler)timeout
Section titled “timeout”Type: number
Default: 60
The visibility timeout (in seconds) - how long a task remains invisible to other workers while being processed.
// Flow levelnew Flow({ slug: 'my_flow', timeout: 120 })
// Step level (overrides flow default).step({ slug: 'my_step', timeout: 300 }, handler)startDelay
Section titled “startDelay”Type: number
Default: 0
Initial delay (in seconds) before task execution.
Configuration Examples
Section titled “Configuration Examples”Flow with Defaults Only
Section titled “Flow with Defaults Only”When all steps can use the same configuration:
new Flow({ slug: 'my_flow', maxAttempts: 3, // Default for all steps baseDelay: 1, // Default for all steps timeout: 60 // Default for all steps}) .step({ slug: 'step1' }, handler1) // Uses flow defaults .step({ slug: 'step2' }, handler2) // Uses flow defaultsMixed Configuration
Section titled “Mixed Configuration”Override flow defaults for specific steps that need different behavior:
new Flow({ slug: 'analyze_data', maxAttempts: 3, // Flow defaults baseDelay: 1, timeout: 60}) .step({ slug: 'fetch_data', // Uses all flow defaults }, fetchHandler) .step({ slug: 'process_data', maxAttempts: 5, // Override: more retries timeout: 300 // Override: needs more time // baseDelay uses flow default (1) }, processHandler) .step({ slug: 'call_api', baseDelay: 10, // Override: longer initial delay // maxAttempts and timeout use flow defaults }, apiHandler)Retry Behavior
Section titled “Retry Behavior”pgflow uses exponential backoff for retries. The delay between attempts is calculated as:
delay = baseDelay * 2^attemptCountRetry Delay Examples
Section titled “Retry Delay Examples”Here’s how retry delays grow with different base delays:
| Attempt | Delay (baseDelay: 2s) | Delay (baseDelay: 5s) | Delay (baseDelay: 10s) |
|---|---|---|---|
| 1 | 2s | 5s | 10s |
| 2 | 4s | 10s | 20s |
| 3 | 8s | 20s | 40s |
| 4 | 16s | 40s | 80s |
| 5 | 32s | 80s | 160s |
| 6 | 64s | 160s | 320s |
| 7 | 128s | 320s | 640s |
When Tasks Fail Permanently
Section titled “When Tasks Fail Permanently”A task is marked as permanently failed when:
- It has been attempted
maxAttemptstimes - Each attempt resulted in an error
- The task status changes from
queuedtofailed - The error message from the last attempt is stored