cleanup all worker stats when starting up servers

This commit is contained in:
2026-04-04 21:28:26 +02:00
parent 79f23b8be6
commit 9d33c6fded
6 changed files with 109 additions and 10 deletions
+12 -1
View File
@@ -2,7 +2,7 @@ import inspect
import json
class RedisMetricsStore:
def __init__(self, redis_url:str="redis://localhost:6379/0", key_prefix:str="snake:metrics:worker", ttl_seconds:int=None, **kwargs):
def __init__(self, redis_url:str="redis://localhost:6379/0", key_prefix:str="snake:metrics:worker", ttl_seconds:int|None=None, **kwargs):
self.redis_url = redis_url
self.key_prefix = key_prefix
self.ttl_seconds = ttl_seconds
@@ -41,6 +41,17 @@ class RedisMetricsStore:
continue
return snapshots
async def clear_all(self) -> None:
redis = await self._get_redis()
keys = await redis.keys(f"{self.key_prefix}:*")
if keys:
await redis.delete(*keys)
async def acquire_startup_cleanup_lock(self, lock_key:str, ttl_seconds:int=300) -> bool:
redis = await self._get_redis()
locked = await redis.set(lock_key, '1', ex=max(1, int(ttl_seconds)), nx=True)
return bool(locked)
async def close(self) -> None:
if self._redis is None:
return