feat(scheduler): shared background-job runner (PMS-135) #69
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/pms-135-scheduler"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
src/scheduler/module providing aJobtrait andSchedulerstruct (register+start) so background jobs no longer copy-paste thetokio::time::interval+MissedTickBehavior::Skip+tracing::warnboilerplate per worker.tracing::info_span!("scheduler_tick", job = ...)composes with PMS-126 service-method instrumentation. Tick errors log atwarnand the loop continues; backoff stays the job's responsibility.tests/scheduler.rssmoke covers two cases: happy-path job ticks at the configured interval; a job that returnsErrevery other tick does not kill the loop.Follow-up (not in this PR)
DispatcherWorker(src/modules/notifications/worker.rs) to implementJoband register via the scheduler. Backoff ladder stays inside the worker.RmmSyncWorker(src/modules/rmm/worker.rs) to implementJoband register via the scheduler.Test plan
cargo fmt --all --check,cargo clippy --all-targets -- -D warnings,cargo test --test scheduler(2/2 pass) via the shared rust-builder image.Closes PMS-135. Last subtask of PMS-121 (cross-cutting server infrastructure).
Replaces the ad-hoc-spawn-per-worker pattern (notifications dispatcher + RMM sync worker, each independently `tokio::spawn`'d from `main.rs`) with a single `Scheduler` registry. Future jobs from PMS-58 (calendar reminders), PMS-64 (contract renewals/expiry), PMS-100 (RMM sync future ticks), and PMS-106 (SLA breach checks) all hang off the same abstraction instead of re-implementing the `tokio::time::interval` + `MissedTickBehavior::Skip` + `tracing::warn!` boilerplate. Shape: ```rust let mut sched = Scheduler::new(); sched.register(notifications_worker, Duration::from_secs(5)); sched.register(rmm_worker, Duration::from_secs(60)); sched.start(); ``` Each registered `Job` runs on its own tokio task so a slow tick on one job does not delay any other. Per-tick `tracing::info_span!("scheduler_tick", job = job.name())` composes with the PMS-126 service-method instrumentation. Tick errors log at `warn` and the loop continues; richer retry semantics (e.g. the notifications dispatcher's 1m/5m/30m/2h/6h backoff ladder) stay inside the `Job::run` impl, not the scheduler, so migration of existing workers is byte-for-byte semantic. This PR only ships the abstraction + `tests/scheduler.rs` smoke (one happy-path job, one job that returns Err every other tick to prove the loop survives). The existing `DispatcherWorker::run_forever` and `RmmSyncWorker::run_forever` entry points are untouched; cut-over to the new API ships in two follow-up PRs (one per worker) so each diff stays small and the existing backoff / dedupe behavior is reviewed against the new shape one worker at a time. #PMS-135