Skip to content

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

PropertyTypeDescription
typestringMust be repeat.
countintegerMaximum number of times to repeat the steps.
repeatOnstring(Optional) Condition to repeat: SUCCESS or FAILURE.
intervalinteger(Optional) Delay in milliseconds between each repetition.
stepsarrayThe nested steps to be repeated.

Behavior

  1. The engine executes the child steps.
  2. After execution, it checks the repeatOn condition:
    • 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 repeatOn is omitted: It simply repeats count times regardless of the outcome.
  3. 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 found

Data 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 count to avoid accidental infinite loops.
  • Interval: Use interval for external API calls to avoid spamming the remote server and getting rate-limited.
  • Error Handling: If the last repetition of a repeatOn: FAILURE block still fails, the entire repeat step will return that final error to the flow.

Released under the ISC License.