REPEAT Step
The REPEAT step is used for re-executing a set of steps multiple times. It is ideal for implementing retry logic or polling an external resource until it reaches a desired state.
Properties
| Property | Type | Description |
|---|---|---|
type | string | Must be repeat. |
count | integer | Maximum number of times to repeat the steps. |
repeatOn | string | (Optional) Condition to repeat: SUCCESS or FAILURE. |
interval | integer | (Optional) Delay in milliseconds between each repetition. |
steps | array | The nested steps to be repeated. |
Behavior
- The engine executes the child
steps. - After execution, it checks the
repeatOncondition:- If
repeatOn: FAILURE: It repeats only if the steps failed (returned an error). If they succeeded, the loop breaks. - If
repeatOn: SUCCESS: It repeats only if the steps succeeded. If they failed, the loop breaks. - If
repeatOnis omitted: It simply repeatscounttimes regardless of the outcome.
- If
- If it needs to repeat, it waits for the
interval(if any) and then starts again.
Example: API Retry Logic
Retry a failing API call up to 3 times with a 1-second delay between attempts.
yaml
- name: "RetryFetch"
type: "repeat"
count: 3
repeatOn: "FAILURE" # Keep trying as long as it fails
interval: 1000 # 1 second wait
steps:
- type: "invoke"
service: "api:GetRemoteData"Example: Simple Polling
Repeat a check 5 times to see if a status has changed.
yaml
- name: "PollStatus"
type: "repeat"
count: 5
interval: 2000
steps:
- type: "invoke"
service: "api:CheckStatus"
# Logic inside could use an EXIT step to break early if 'DONE' is foundData Flow Scenario: Successful Retry
Initial Pipeline:
json
{ "retryCount": 0 }After 1st Attempt (Failed):
json
{ "retryCount": 1 }After 2nd Attempt (Succeeded):
json
{ "retryCount": 2, "status": "Success" }(Note: Since the 2nd attempt succeeded and repeatOn is FAILURE, the loop stops)
Tips
- Safety First: Always provide a
countto avoid accidental infinite loops. - Interval: Use
intervalfor external API calls to avoid spamming the remote server and getting rate-limited. - Error Handling: If the last repetition of a
repeatOn: FAILUREblock still fails, the entire repeat step will return that final error to the flow.
