This hello-world example demonstrates three foundational workflow patterns:
- A minimal task definition (
calculateSquare) - A task that chains runs of another task (
sumSquares) - A task with custom retry behavior (
flipCoin)
- How to define tasks with
task(...) - How to chain task runs using
awaitandPromise.all - How to customize retry behavior with
retry
The smallest possible task: takes one number and returns its square.
Chains two runs of calculateSquare and sums the results.
It uses Promise.all(...) to chain the two runs in parallel:
const [result1, result2] = await Promise.all([
calculateSquare(a),
calculateSquare(b),
]);Simulates a coin flip:
- Heads: Returns success
- Tails: Raises an error to trigger retry
Retry policy in this example:
- max retries:
3 - wait duration:
1000ms - backoff scaling:
1.5
- Node.js 18+
Make sure you've installed the latest version of the Render CLI.
-
From this template's root, start the local task server:
npm install render workflows dev -- npm start
-
In a separate terminal, trigger task runs:
render workflows tasks start calculateSquare --local --input='[5]' render workflows tasks start sumSquares --local --input='[3,4]' render workflows tasks start flipCoin --local --input='[]'
Expected behavior:
calculateSquarewith5returns25sumSquareswith3,4returns25flipCoinmay fail and retry before succeeding
Configure your Workflow service with:
| Option | Value |
|---|---|
| Build command | npm install |
| Start command | npm start |
Any call to task({ name: ... }, handler) registers a runnable workflow task.
Inside an async task, calling await anotherTask(...) chains a run of that task.
Use the retry option in task config when transient failures should be retried automatically.
- Confirm the service is running
- Verify task names exactly match:
calculateSquare,sumSquares,flipCoin
- Confirm dependency install completed from
package.json - Confirm Node.js version is 18+