OzWrapper.OzAnomaly.scheduler.Scheduler

class OzWrapper.OzAnomaly.scheduler.Scheduler(store: object, device_id: str, *, prefix: str = 'anomaly:last_run')

Tracks last-run timestamp per device for the anomaly detector.

Variables:
  • store – Object exposing get(key) and set(key, value). In production: the Redis client held by Manager.OzCache. In tests: a plain dict (which satisfies both methods).

  • device_id – Device identifier — keys are namespaced per device.

  • prefix – Key prefix. Defaults to "anomaly:last_run".

_key() str
get_last_run_seconds() int | None

Return the unix-second timestamp of the last recorded run.

Returns None if the detector has never run on this device, if the store lookup raised, or if the stored value isn’t an int. Callers should treat None as “due”.

is_due(schedule_hours: float) bool

Return True when schedule_hours have elapsed since the last run.

Fractional hours are supported — pass e.g. 0.25 for a 15-minute cadence. First-ever call (no stored timestamp) is always due. A store-layer failure is also treated as due — over-running once on the next loop tick is preferable to silently skipping a window.

mark_run() None

Record that the detector ran right now (best-effort, non-fatal).

device_id
prefix = 'anomaly:last_run'
store