Skip to content

feat: add database-backed scheduler#2

Merged
winetree94 merged 8 commits into
mainfrom
feat/database-scheduler
May 13, 2026
Merged

feat: add database-backed scheduler#2
winetree94 merged 8 commits into
mainfrom
feat/database-scheduler

Conversation

@winetree94
Copy link
Copy Markdown
Contributor

@winetree94 winetree94 commented May 13, 2026

Summary

  • Add database-backed scheduler mode with durable scheduled-job and background-job storage
  • Harden distributed lease acquisition/renewal/completion semantics for multi-instance runners
  • Abort cooperative scheduled/background handlers via JobRunContext.signal when lease renewal detects lost ownership
  • Improve CAS contention handling so a failed lock attempt continues scanning other due jobs in the same tick
  • Add JSON-safe background job payload validation to reject unsupported values before persistence
  • Add completed background-job retention cleanup with configurable background_retention_ms (default 7 days)
  • Document database scheduler configuration, retention behavior, and instance/lock owner semantics
  • Cover scheduler, background queue, standalone config, and lease-loss edge cases with regression tests

Test Plan

  • corepack pnpm --filter @tinyrack/tinyauth-server test -- --run src/entrypoints/scheduler/database.test.ts
  • corepack pnpm test
  • corepack pnpm build
  • corepack pnpm biome check .
  • git diff --check

Notes

  • instanceId remains internally generated by default (hostname:pid:uuid) to avoid lock-owner collisions across replicas; the programmatic override is kept for tests/debugging.
  • Lease-loss abort is cooperative: handlers receive an AbortSignal and can stop side effects promptly when renewal returns false; completion is still protected by the existing DB lease fencing.
  • Background retention cleanup only deletes terminal jobs (succeeded/failed) with completedAt older than the configured retention window; pending/running jobs are never removed by cleanup.

@winetree94 winetree94 merged commit f2d0e60 into main May 13, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant