Skip to content

Wait for a background job

critters/admin/flows/export.yml
name: Export orders
steps:
- request: exports/create.yml
expect: 202
capture:
jobId: res.body.jobId
- tool: poll
request: exports/status.yml
with:
jobId: "{{jobId}}"
until:
- expression: res.body.state
operator: in
value: done, failed
capture:
state: res.body.state
downloadUrl: res.body.url
rows: res.body.rowCount
every: 5
timeout: 300
- tool: assert
checks:
- { expression: "{{state}}", operator: eq, value: done }
- { expression: "{{rows}}", operator: gt, value: "0" }
- request: exports/download.yml
with:
url: "{{downloadUrl}}"
expect: 200

until stops on done or failed. The assert step then fails the flow with the actual state, instead of waiting until the timeout.

Connection errors count as “not done yet”:

- tool: poll
request: health.yml
until:
- { expression: res.status, operator: eq, value: "200" }
every: 1
timeout: 60
- tool: poll
request: search/users.yml
with: { q: "{{email}}" }
until:
- { expression: res.body.hits, operator: isNotEmpty }
timeout: 20