Zebflow Docs
logic.retry
Zebflow Docs

logic.retry

Runs a failed or not-yet-ready node again, with a delay and a budget

logic.retry --max-attempts N [--delay DURATION] [--backoff N] [--max-delay DURATION] [--max-elapsed DURATION] [--when EXPR]

Runs a failed or not-yet-ready node again, with a delay and a budget. It is fed either way. From an :error pin ([b]:error -> [r]): it receives the failure — the payload kept, the failing node's key answering { ok: false, error: { code, message } } — and fires retry with the failing node's input given back (wire [r]:retry -> [b]) until --max-attempts is spent, then failed with the last failure (input.<noun>.error.code); a refused-class error goes straight to failed. From an ordinary edge ([check] -> [r]): the payload is a verdict — retry: true on it, or --when "<expr>" true (JavaScript over input, as logic.if --when), fires retry with that payload; false passes it through on done; the budget spent fires failed. A poll loop waits this way without throwing, so the canvas shows a wait, never a failure. --delay waits between attempts (a duration: 500ms, 5s); --backoff 2 doubles that wait each attempt, --max-delay caps the grown wait, and --max-elapsed is a wall-time budget from the first attempt — whichever budget runs out first fires failed, and __zf_retry.reason names it. Attempts are counted in __zf_retry.attempt ($nodes.<r>.__zf_retry); a retry loop without a failed edge swallows the give-up.

Flags

  • --max-attempts (required): Maximum total attempts before routing to failed.
  • --delay: Optional wait before retrying (500ms, 5s); the first wait when --backoff grows it.
  • --backoff: Factor the delay grows by each attempt: 1 (default) is a fixed delay, 2 doubles it (500ms, 1s, 2s, …).
  • --max-delay: Cap for a delay grown by --backoff (8s).
  • --max-elapsed: Wall-time budget from the first attempt (30s, 5m); when spent (or the next wait would overrun it) failed fires even with attempts left.
  • --when: Verdict expression for a payload from an ordinary edge (JavaScript over input, like logic.if --when); true retries, false is done. Without it the payload's retry: true is the verdict.

Examples

Three attempts at a flaky API

| logic.retry --max-attempts 3 --delay 500ms

Graph: [b] http.response.fetch …, [b]:error -> [r], [r]:retry -> [b], [r]:failed -> [e] web.response.send --status 502.

A rate-limited API

| logic.retry --max-attempts 6 --delay 500ms --backoff 2 --max-delay 8s

The waits grow 500ms, 1s, 2s, 4s, 8s — the cap holds the last one. Add --max-elapsed 30s to give up on wall time instead of on the count; __zf_retry.reason on the failed payload says which budget ran out.

Poll until a job is ready

| logic.retry --max-attempts 40 --delay 5s --when "input.script.retry"

Graph: [poll] http.response.fetch …, [check] javascript.script.run -- return { retry: input.response.body.status !== 'success', url: input.response.body.videoURL }, [poll] -> [check], [check] -> [wait], [wait]:retry -> [poll], [wait]:done -> [download], [wait]:failed -> [gaveup]. The check never throws; --when reads its answer: true is the wait, false goes on through done.

Input:

json
{  "script": {    "retry": true,    "url": null  }}