WIP autoscaler agent
This commit is contained in:
parent
c610a3e284
commit
28059dcedf
34 changed files with 2409 additions and 35 deletions
39
agent/nix_builder_autoscaler/providers/clock.py
Normal file
39
agent/nix_builder_autoscaler/providers/clock.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
"""Injectable clock abstraction for testability."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from typing import Protocol
|
||||
|
||||
|
||||
class Clock(Protocol):
|
||||
"""Clock protocol — provides current UTC time."""
|
||||
|
||||
def now(self) -> datetime: ...
|
||||
|
||||
|
||||
class SystemClock:
|
||||
"""Real wall-clock implementation."""
|
||||
|
||||
def now(self) -> datetime:
|
||||
"""Return the current UTC time."""
|
||||
return datetime.now(UTC)
|
||||
|
||||
|
||||
class FakeClock:
|
||||
"""Deterministic clock for tests."""
|
||||
|
||||
def __init__(self, start: datetime | None = None) -> None:
|
||||
self._now = start or datetime(2026, 1, 1, tzinfo=UTC)
|
||||
|
||||
def now(self) -> datetime:
|
||||
"""Return the fixed current time."""
|
||||
return self._now
|
||||
|
||||
def advance(self, seconds: float) -> None:
|
||||
"""Advance the clock by the given number of seconds."""
|
||||
self._now += timedelta(seconds=seconds)
|
||||
|
||||
def set(self, dt: datetime) -> None:
|
||||
"""Set the clock to an exact time."""
|
||||
self._now = dt
|
||||
Loading…
Add table
Add a link
Reference in a new issue