Skip to content
Source
Sign inSign up
TanStack/workflow

docs(research): cron and scheduling landscape #4

Mergedtannerlinsleymerged 2 commits intomain fromrefs/pull/4/headmerged by tannerlinsley

Showing 5 changed files with 226 additions and 0 deletions (loading 3).

x
0 of 5 viewed, 5 left
222 additions and 0 deletionsdocs/concepts/scheduling.mdAdded
View file
@@ -0,0 +1,222 @@
+# Scheduling and recurring runs
+​
+`@tanstack/workflow-core` ships no cron primitive. The shape every mature workflow engine converges on — Inngest, Trigger.dev, Temporal, Hatchet, DBOS — is **external scheduler + fresh workflow invocation per tick**. Bring your own scheduler. The engine doesn't need to know.
+​
+This page is recipes for that pattern.
+​
+## The model in one paragraph
+​
+You declare a normal workflow. Something outside the engine (cron daemon, EventBridge, Durable Object alarm, Vercel Cron Job, a `setInterval` in a worker, anything) fires on schedule. Each tick calls `runWorkflow({ workflow, input, runStore })` with fresh input. The workflow runs end-to-end and finishes; the next tick is a new `runId`. No "loop forever with sleep" — log doesn't grow, replay cost is constant, and "when's the next run?" is answerable from the scheduler, not from the engine.
+​
+## Recipe: a node process with `node-cron`
+​
+```ts
+import cron from 'node-cron'
+import { runWorkflow, inMemoryRunStore } from '@tanstack/workflow-core'
+import { dailyReport } from './workflows/daily-report'
+​
+const runStore = inMemoryRunStore() // swap for a durable adapter in prod
+​
+// 09:00 every Monday in UTC
+cron.schedule(
+ '0 9 * * MON',
+ async () => {
+ for await (const _ of runWorkflow({
+ workflow: dailyReport,
+ input: { triggeredAt: Date.now() },
+ runStore,
+ })) {
+ // events flow through here — forward to Redis, log, ignore
+ }