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
ctx.runandPromise.all - How to customize retry behavior with
retry
Every task takes a TaskContext as its first parameter, followed by its inputs.
The workflow system supplies the context, so the inputs you pass with
--input start after it.
The smallest possible task: takes one number and returns its square. It runs no other tasks, so it never touches the context.
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([
ctx.run(calculateSquare, a),
ctx.run(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.
task(...) returns a task definition, which is not callable on its own — pass
it to ctx.run to run it.
Inside an async task, await ctx.run(anotherTask, ...inputs) runs that task on
its own compute and resolves with its result.
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+