Coverage for src/retrospeedlab/runner/schedule.py: 63%

19 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-12-03 23:09 +0000

1from dataclasses import asdict, dataclass 

2 

3import httpx 

4from loguru import logger 

5 

6SCHEDULE_PATH = "/rotation" 

7API_KEY_HEADER = "x-api-key" 

8 

9 

10@dataclass(slots=True, frozen=True) 

11class ScheduledTurn: 

12 starts_at: str 

13 ends_at: str 

14 best_runs: bool 

15 games: list[str] 

16 

17 

18def publish_schedule(client: httpx.Client, api_key: str, turns: list[ScheduledTurn]) -> None: 

19 try: 

20 response = client.put( 

21 SCHEDULE_PATH, json={"turns": [asdict(turn) for turn in turns]}, headers={API_KEY_HEADER: api_key} 

22 ) 

23 response.raise_for_status() 

24 except httpx.HTTPError as error: 

25 logger.warning(f"The backend did not take the stream schedule: {error}") 

26 return 

27 logger.info(f"Published the schedule of the next {len(turns)} turns")