Render Tutorials
Stock research: from flaky to reliable

Trigger task runs from the web

⏱ 10 min

The web service still runs research(), but each search becomes a remote task run after you create the second service. Synthesis stays on the web service.

This page follows Render API docs. Code only: searches will not finish until that service is wired up.

A. SDK on the server

In server/package.json:

server/package.json
"@renderinc/sdk": "^0.5.1"
Terminal
$cd server && npm install
added @renderinc/sdk

Import Render from @renderinc/sdk.

B. Update tasks/src/research.ts

Remove:

import { searchOne } from './search.js'

Add:

tasks/src/research.ts
import { Render } from '@renderinc/sdk'
import type { ResearchEvent, SearchResult } from '../../shared/types.js'
const serviceSlug = process.env.WORKFLOW_SERVICE_SLUG ?? 'your-service-slug'
const pollMs = parseInt(process.env.WORKFLOW_POLL_MS ?? '1500', 10)
const render = new Render()

Polling helper (paste after the constants):

tasks/src/research.ts
async function waitForSearchTask(taskRunId: string): Promise<SearchResult> {
while (true) {
const details = await render.workflows.getTaskRun(taskRunId)
if (details.status === 'completed') {
const result = details.results?.[0] as SearchResult | undefined
if (!result) throw new Error('searchOne returned no result')
return result
}
if (details.status === 'failed' || details.status === 'canceled') {
throw new Error(details.error ?? `searchOne ${details.status}`)
}
await new Promise((r) => setTimeout(r, pollMs))
}
}

Inside searches.map, replace only the searchOne call:

tasks/src/research.ts
const started = await render.workflows.startTask(
`${serviceSlug}/searchOne`,
[query, spec, index],
)
const result = await waitForSearchTask(started.taskRunId)
  • taskIdentifier: {service-slug}/{task-name}.
  • inputData: positional JSON array matching searchOne(query, spec, index).
  • started.taskRunId: available immediately from startTask.

Leave onEvent, buildQueries, synthesize, and the Promise.all structure unchanged.

Push

Terminal
$npm run build
Build succeeded at repo root
$git add -A && git commit -m "Dispatch searchOne via task-run SDK"
[main abc1234] Dispatch searchOne via task-run SDK
$git push
To github.com:YOUR_GITHUB_USER/workshop-demo.git

What you learned

  • Server imports Render from @renderinc/sdk
  • startTask fires remote runs; getTaskRun polls until terminal status
  • Four parallel dispatches still use Promise.all from the web process