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

tannerlinsleycommented

Adds `research/SCHEDULING.md` — a comparison of how Inngest, Trigger.dev, Temporal, Cloudflare Workflows, Hatchet, DBOS, Restate, AWS Step Functions, Vercel WDK, Mastra, and LangGraph.js handle cron / recurring execution.

Why

Came up while answering "how do other libraries handle cron?" — worth saving as a sketchpad entry rather than relitigating later.

Key takeaways

  • Every mature engine separates the cron metadata from the workflow body and fires fresh invocations per tick.
  • Nobody runs production recurring workflows as "loop forever with sleep" — log growth, replay cost, and overlap-policy visibility all push toward fresh-invocation.
  • Temporal's six-mode overlap-policy enum is the gold standard worth copying.
  • Restate's self-rescheduling pattern is interesting but probably not the primary model.

Implications

The closure engine needs no changes for cron. A future `@tanstack/workflow-cron` package would be small (schedule definitions + a polling driver). Recommend deferring until at least one durable storage adapter ships.

Test plan

  • Docs-only change, no source touched
  • `pnpm format` clean
  • CI green

Summary by CodeRabbit

  • Documentation

    • Clarified the research README to frame design notes as historical context and decision-point sketches
    • Added a research note on recurring scheduling/cron patterns and proposed package architecture
    • Introduced a user-facing Scheduling concept doc with concrete external-scheduler recipes and overlap strategies
    • Updated site navigation to surface Scheduling documentation
  • Tests

    • Added end-to-end tests exercising external cron scheduling and overlap-handling scenarios (skip-overlap, buffer-one)

Review Change Stack

    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      📝 Walkthrough

      Walkthrough

      Research documentation is added to the TanStack Workflow repository with a new scheduling and cron landscape analysis. The research directory README is clarified to better characterize design notes, and a new SCHEDULING.md document is cataloged that surveys recurring execution patterns across major workflow engines.

      Changes

      Workflow Scheduling Research and Documentation

      Layer / File(s)Summary
      README clarification and SCHEDULING.md catalog entry
      research/README.md
      Design notes disclaimer reworded to emphasize they are decision-point snapshots, not living documentation. Contents table extended with a new entry for SCHEDULING.md describing forward-looking cron and recurring execution research.
      Concepts: external-scheduler recipes and overlap policies
      docs/concepts/scheduling.md
      Adds the external-scheduler model and concrete recipes for Node (node-cron), Cloudflare Worker cron, Vercel cron HTTP routes, and AWS EventBridge → Lambda. Describes skip-overlap and buffer-one overlap policies, schedule-store polling guidance, and references the test example.
      Docs navigation update
      docs/config.json
      Inserted a "Scheduling" navigation child under Concepts pointing to concepts/scheduling.
      External-cron tests: header and imports
      packages/workflow-core/tests/examples.external-cron.test.ts
      New Vitest test module and imports documenting the external-scheduler pattern.
      Test: one-shot workflow factory
      packages/workflow-core/tests/examples.external-cron.test.ts
      Shared one-shot workflow factory used in tests defining input validation, generation and email steps, and returned output.
      Test: scheduler helper abstraction
      packages/workflow-core/tests/examples.external-cron.test.ts
      Minimal setInterval-based scheduler helper used to drive periodic ticks under fake timers.
      Test: three-tick fresh-run behavior
      packages/workflow-core/tests/examples.external-cron.test.ts
      Test that verifies each tick starts a fresh workflow run with distinct runIds and produces expected finished outputs.
      Test: skip-overlap behavior
      packages/workflow-core/tests/examples.external-cron.test.ts
      Test simulating deterministic runId checks to skip starting a second run while a previous run is still in-flight.
      Test: buffer-one behavior
      packages/workflow-core/tests/examples.external-cron.test.ts
      Test that collapses multiple ticks occurring during a long-running execution into a single buffered follow-up run.
      SCHEDULING.md research document
      research/SCHEDULING.md
      New research document surveying timer primitives, cross-system cron implementations, extracted recurring patterns, a proposed cron-package architecture with deployment options, and open design questions; marked research-only and links to user recipes and the test example.

      Estimated code review effort

      🎯 2 (Simple) | ⏱️ ~10 minutes

      Poem

      🐰 A research scroll unfurls, Cron patterns swirl and dance, Temporal gears, schedules twirled— No engines changed, just glance! Sweet documentation's gift, ✨

      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 33.33% which is insufficient. The required threshold is 80.00%.Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title accurately captures the main change: adding research documentation comparing how various workflow engines handle cron and scheduling patterns.
      Description check✅ PassedThe PR description is largely complete with clear motivation, key takeaways, and implications, but is missing the standard checklist items and release impact sections from the template.
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      ✏️ Tip: You can configure your own custom pre-merge checks in the settings.
      ✨ Finishing Touches
      📝 Generate docstrings
      • Create stacked PR
      • Commit on current branch

      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    2. Actionable comments posted: 1

      🤖 Prompt for all review comments with AI agents
      Verify each finding against current code. Fix only still-valid issues, skip the
      rest with a brief reason, keep changes minimal, and validate.
      
      Inline comments:
      In `@research/SCHEDULING.md`:
      - Line 70: The bullet starting with "A driver — polls a schedule store, computes
      'next fire time,' fires `runWorkflow`." is a sentence fragment; update it to
      include an explicit subject and verb so it's a complete sentence (e.g., "A
      driver polls a schedule store, computes the next fire time, and fires
      `runWorkflow`."). Edit the line in SCHEDULING.md to replace the fragment with a
      full sentence while preserving the examples (Durable Object alarm, AWS Lambda +
      EventBridge, Cloudflare Cron Trigger) and backtick formatting for `runWorkflow`.
      🪄 Autofix (Beta)

      Fix all unresolved CodeRabbit comments on this PR:

      • Push a commit to this branch (recommended)
      • Create a new PR with the fixes

      ℹ️ Review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      Run ID: 7b864385-b4cb-47cc-af0a-77ec90021ada

      📥 Commits

      Reviewing files that changed from the base of the PR and between 214ac78b4ebe701beba006caf1ceadefe4a1912f and 30e46ba4052ab341ff2714d6d0da9d7afd825f6a.

      📒 Files selected for processing (2)
      • research/README.md
      • research/SCHEDULING.md
      @@ -0,0 +50,21 @@
      50+
      51+```ts
      52+// Hypothetical
      53+import { createSchedule, runSchedules } from '@tanstack/workflow-cron'
      54+
      55+createSchedule({
      56+ id: 'daily-report',
      57+ workflow: dailyReport, // a normal workflow definition
      58+ cron: '0 9 * * MON',
      59+ input: () => ({ runId: crypto.randomUUID() }),
      60+ overlapPolicy: 'skip', // skip | buffer | cancel-previous | allow
      61+})
      62+
      63+// Run by a worker process (or DO alarm, or AWS scheduled task)
      64+await runSchedules({ runStore, scheduleStore })
      65+```
      66+
      67+Two pieces:
      68+
      69+- **Schedule definitions** — declarative, sit next to workflow definitions.
      70+- **A driver** — polls a schedule store, computes "next fire time," fires `runWorkflow`. Can be deployed as a long-running worker, Durable Object alarm, AWS Lambda + EventBridge, Cloudflare Cron Trigger, etc.
      coderabbitai[bot](GitHub profile, opens in a new tab)commented

      ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

      Fix sentence fragment for readability.

      Line 70 reads as a fragment after the previous sentence. Add an explicit subject to keep the bullet grammatically complete.

      Suggested edit
      -- **A driver** — polls a schedule store, computes "next fire time," fires `runWorkflow`. Can be deployed as a long-running worker, Durable Object alarm, AWS Lambda + EventBridge, Cloudflare Cron Trigger, etc.
      +- **A driver** — polls a schedule store, computes "next fire time," and fires `runWorkflow`. It can be deployed as a long-running worker, Durable Object alarm, AWS Lambda + EventBridge, Cloudflare Cron Trigger, etc.
      📝 Committable suggestion

      ‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

      Suggested change
      70-- **A driver** — polls a schedule store, computes "next fire time," fires `runWorkflow`. Can be deployed as a long-running worker, Durable Object alarm, AWS Lambda + EventBridge, Cloudflare Cron Trigger, etc.
      70+- **A driver** — polls a schedule store, computes "next fire time," and fires `runWorkflow`. It can be deployed as a long-running worker, Durable Object alarm, AWS Lambda + EventBridge, Cloudflare Cron Trigger, etc.
      🧰 Tools
      🪛 LanguageTool

      [style] ~70-~70: To form a complete sentence, be sure to include a subject. Context: ... "next fire time," fires runWorkflow. Can be deployed as a long-running worker, D...

      (MISSING_IT_THERE)

      🤖 Prompt for AI Agents
      Verify each finding against current code. Fix only still-valid issues, skip the
      rest with a brief reason, keep changes minimal, and validate.
      
      In `@research/SCHEDULING.md` at line 70, The bullet starting with "A driver —
      polls a schedule store, computes 'next fire time,' fires `runWorkflow`." is a
      sentence fragment; update it to include an explicit subject and verb so it's a
      complete sentence (e.g., "A driver polls a schedule store, computes the next
      fire time, and fires `runWorkflow`."). Edit the line in SCHEDULING.md to replace
      the fragment with a full sentence while preserving the examples (Durable Object
      alarm, AWS Lambda + EventBridge, Cloudflare Cron Trigger) and backtick
      formatting for `runWorkflow`.
    3. Actionable comments posted: 1

      🤖 Prompt for all review comments with AI agents
      Verify each finding against current code. Fix only still-valid issues, skip the
      rest with a brief reason, keep changes minimal, and validate.
      
      Inline comments:
      In `@packages/workflow-core/tests/examples.external-cron.test.ts`:
      - Around line 179-188: The test uses vi.advanceTimersByTimeAsync(0) to try to
      ensure tick1 reached the held step, which is flaky; change it to use an explicit
      "step started" latch like the existing pattern used elsewhere in the file: add a
      promise/resolver pair (e.g., stepStartedPromise and resolveStepStarted) inside
      the held step callback that is resolved when the step begins, await that promise
      after creating tick1 (instead of awaiting vi.advanceTimersByTimeAsync(0)), then
      create tick2 via tickWithSkipOverlap(), and only call releaseFirstStep() after
      the latch ensures the first step is actually running; reference the existing
      latch implementation in the file to mirror naming and setup.
      🪄 Autofix (Beta)

      Fix all unresolved CodeRabbit comments on this PR:

      • Push a commit to this branch (recommended)
      • Create a new PR with the fixes

      ℹ️ Review info
      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro

      Run ID: f1db5e9b-bc53-4b35-8901-f96f814b97da

      📥 Commits

      Reviewing files that changed from the base of the PR and between 30e46ba4052ab341ff2714d6d0da9d7afd825f6a and 7f45a5589e3633f038ca75bd37a68dd2fc1f26a4.

      📒 Files selected for processing (4)
      • docs/concepts/scheduling.md
      • docs/config.json
      • packages/workflow-core/tests/examples.external-cron.test.ts
      • research/SCHEDULING.md
      ✅ Files skipped from review due to trivial changes (1)
      • research/SCHEDULING.md
      @@ -0,0 +168,21 @@
      168+ // Easier: hold the first tick's `step` fn open by making it await
      169+ // a manually-resolved promise.
      170+ let releaseFirstStep: (() => void) | null = null
      171+ workFn.mockImplementationOnce(async () => {
      172+ invocations++
      173+ await new Promise<void>((r) => {
      174+ releaseFirstStep = r
      175+ })
      176+ return { summary: 'first' }
      177+ })
      178+
      179+ const tick1 = tickWithSkipOverlap()
      180+ // Yield so tick1 progresses to inside the step fn and is "running".
      181+ await vi.advanceTimersByTimeAsync(0)
      182+
      183+ // Fire tick2 — same minute window, first is still running.
      184+ const tick2 = tickWithSkipOverlap()
      185+ await vi.advanceTimersByTimeAsync(0)
      186+
      187+ // Release the first tick.
      188+ releaseFirstStep!()
      coderabbitai[bot](GitHub profile, opens in a new tab)commented

      ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

      Avoid timer-yield synchronization in skip-overlap test; use an explicit “step started” latch.

      await vi.advanceTimersByTimeAsync(0) does not reliably guarantee tick1 reached the held step, so releaseFirstStep!() can race and make this test flaky. Use a promise latch (same pattern as Line 207-Line 209) before firing tick2.

      Proposed deterministic fix
      +    let firstStepStarted: (() => void) | null = null
      +    const firstStepStartedPromise = new Promise<void>((r) => {
      +      firstStepStarted = r
      +    })
           let releaseFirstStep: (() => void) | null = null
           workFn.mockImplementationOnce(async () => {
             invocations++
      +      firstStepStarted!()
             await new Promise<void>((r) => {
               releaseFirstStep = r
             })
             return { summary: 'first' }
           })
      
           const tick1 = tickWithSkipOverlap()
      -    // Yield so tick1 progresses to inside the step fn and is "running".
      -    await vi.advanceTimersByTimeAsync(0)
      +    // Deterministically wait until tick1 is inside the held step.
      +    await firstStepStartedPromise
      
           // Fire tick2 — same minute window, first is still running.
           const tick2 = tickWithSkipOverlap()
      -    await vi.advanceTimersByTimeAsync(0)
      
           // Release the first tick.
           releaseFirstStep!()
      🤖 Prompt for AI Agents
      Verify each finding against current code. Fix only still-valid issues, skip the
      rest with a brief reason, keep changes minimal, and validate.
      
      In `@packages/workflow-core/tests/examples.external-cron.test.ts` around lines 179
      - 188, The test uses vi.advanceTimersByTimeAsync(0) to try to ensure tick1
      reached the held step, which is flaky; change it to use an explicit "step
      started" latch like the existing pattern used elsewhere in the file: add a
      promise/resolver pair (e.g., stepStartedPromise and resolveStepStarted) inside
      the held step callback that is resolved when the step begins, await that promise
      after creating tick1 (instead of awaiting vi.advanceTimersByTimeAsync(0)), then
      create tick2 via tickWithSkipOverlap(), and only call releaseFirstStep() after
      the latch ensures the first step is actually running; reference the existing
      latch implementation in the file to mirror naming and setup.
    4. tannerlinsley merged this721d546

    5. tannerlinsley closed this

Sign in to join this conversation.