cleanup all worker stats when starting up servers
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user