Commit Graph
2 Commits
Author SHA1 Message Date
sam dd3ae02472 fix(scheduling): respect configuration ownership 2026-09-14 23:25:09 +10:00
sam da07c39ca8 feat(scheduling): ticker engine with configurable interval and pools
Adds internal/domain/scheduling, the timing half of the cron/scheduling
epic (archie-core-1786637496320-249-be6d9a20): a tick loop that asks a
JobSource what is due at a configurable cadence and dispatches each due
job to the pool it declares.

The package owns *when* a scheduled job runs and nothing else. The job
store, blueprints and delivery routing are separate issues in that epic,
so the engine declares the two contracts it needs from them (JobSource,
Runner) and names no implementation. That is what lets the timing
behaviour be tested against a fake clock with no store, no NATS and no
model.

Behaviour worth stating explicitly, because each is load-bearing:

- The source is authoritative about what is due. The engine applies no
  schedule arithmetic of its own, so cron expressions, fixed intervals
  and catch-up windows stay the store's decision.
- A job never overlaps itself. While a run is queued or in flight, later
  ticks reporting the same ID are skipped rather than stacked, so a job
  slower than the interval runs back-to-back instead of fanning out.
- The pools do not interfere: a blocked sequential job cannot delay a
  parallel one, and a saturated parallel cap cannot delay the sequential
  worker. They share only the tick.
- An empty Pool means sequential, not parallel. Wrongly serialising a
  job costs latency; wrongly parallelising one costs correctness.
- Every failure is contained and reported: source error, job error, job
  panic and job timeout each emit an event and leave the loop running.
- Stop drains gracefully. Run contexts descend from Background rather
  than the loop context, so halting the loop stops new work without
  yanking the context out from under a run already in progress; the
  caller's deadline is what eventually cancels those.
- An engine is single-use. Restarting after Stop is refused because Stop
  leaves the dropped backlog and the claims of runs it did not wait for
  behind, and a restart would re-run stale queued jobs while permanently
  suppressing the claimed ones.

internal/events gains job_run/job_error: a scheduled run has no task and
no chat turn behind it, so without those kinds a job that fired, stalled
or failed is invisible everywhere.
2026-08-24 13:28:45 +10:00