Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

Hello World - Render Workflows (TypeScript)

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)

What You'll Learn

  • How to define tasks with task(...)
  • How to chain task runs using ctx.run and Promise.all
  • How to customize retry behavior with retry

Example Tasks

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.

calculateSquare(ctx, a: number): number

The smallest possible task: takes one number and returns its square. It runs no other tasks, so it never touches the context.

sumSquares(ctx, a: number, b: number): Promise<number>

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),
]);

flipCoin(ctx): string

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

Local Development

Prerequisites

  • Node.js 18+

Run locally

Make sure you've installed the latest version of the Render CLI.

  1. From this template's root, start the local task server:

    npm install
    render workflows dev -- npm start
  2. 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:

  • calculateSquare with 5 returns 25
  • sumSquares with 3,4 returns 25
  • flipCoin may fail and retry before succeeding

Deploying to Render

Configure your Workflow service with:

Option Value
Build command npm install
Start command npm start

Key Concepts

Task registration

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.

Chaining runs

Inside an async task, await ctx.run(anotherTask, ...inputs) runs that task on its own compute and resolves with its result.

Retries

Use the retry option in task config when transient failures should be retried automatically.

Troubleshooting

"Task not found"

  • Confirm the service is running
  • Verify task names exactly match: calculateSquare, sumSquares, flipCoin

Import or dependency issues

  • Confirm dependency install completed from package.json
  • Confirm Node.js version is 18+

Resources