This template runs a minimal multi-step job as a Neon Function. Upstash Workflow checkpoints each context.run, retries only the steps that fail, and hands context.sleep timers to QStash, so the function stops running while it waits. The function stores job state in Lakebase Postgres.
How it works
POST /api/jobsstarts a workflow run through QStash.- QStash calls
POST /api/workflowonce per step:start-jobinserts the job with statusrunningwait-before-finishingsleeps durably for 5 secondsfinish-jobmarks the jobcompleted
GET /api/jobs/:idshows the current row, so you can see the job change fromrunningtocompleted.- Upstash Workflow retries a failed step without re-running the steps that already succeeded.
| Route | Purpose |
|---|---|
POST /api/jobs | Start a workflow run |
GET /api/jobs/:id | Read a job's current state |
POST /api/workflow | QStash's signed workflow endpoint |
GET / | Route index |
Scaffold it
Install the latest Neon CLI, then create the function from the registry:
npm install -g neon@latest
neon login
neon link
neon functions new upstash-workflow --slug upstashworkflowThe CLI writes functions/upstashworkflow/index.ts, declares the function in neon.ts, and adds the QStash keys to .env.example.
Configure Upstash
Create a free account at console.upstash.com, open QStash, pick a region, and copy all four values from the Quickstart section into .env.local:
QSTASH_URL="https://qstash.upstash.io"
QSTASH_TOKEN="eyJVc2VySUQiOi..."
QSTASH_CURRENT_SIGNING_KEY="sig_..."
QSTASH_NEXT_SIGNING_KEY="sig_..."







