Coverage for dispatch/redis_keys.py: 94%

16 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2026-07-24 16:42 +0000

1"""Centralized Redis key naming for the pull-dispatch namespace (spec §8). 

2 

3Pure constants and functions — no I/O. Job-related keys are defined now even 

4though this slice does not use them, so the whole §8 schema lives in one place. 

5""" 

6 

7# --- identity (soft state; ADR-0004) ------------------------------------ 

8# ZSET: member=rn_id, score=last heartbeat epoch 

9RUNNERS_REGISTERED = 'runners:registered' 

10 

11# --- job queue ---------------------------------------------------------- 

12JOBS_PENDING = 'jobs:pending' # LIST of pending jb_id 

13JOBS_LEASED = 'jobs:leased' # SET of leased jb_id 

14DISPATCH_LAST_RECOVERY = 'dispatch:last_recovery' # STRING time gate (SET NX EX) 

15 

16 

17def runner_meta(runner_id: str) -> str: 

18 """HASH {name, registered_at, registration_ip}, TTL 7d.""" 

19 return f'runner:{runner_id}:meta' 

20 

21 

22def runner_token_hash(runner_id: str) -> str: 

23 """STRING SHA-256(rk_token), TTL 7d.""" 

24 return f'runner:{runner_id}:token_hash' 

25 

26 

27def runner_alive(runner_id: str) -> str: 

28 """STRING "1", TTL 30s — monitoring only, never used for decisions.""" 

29 return f'runner:{runner_id}:alive' 

30 

31 

32def job(job_id: str) -> str: 

33 """HASH holding a job's full state.""" 

34 return f'job:{job_id}' 

35 

36 

37def submission_current_job(submission_id: str) -> str: 

38 """STRING currency pointer (INV4).""" 

39 return f'submission:{submission_id}:current_job' 

40 

41 

42def submission_job_lock(submission_id: str) -> str: 

43 """Per-submission serialization lock (INV3).""" 

44 return f'submission:{submission_id}:job_lock'