feat(B-RED): Zentraler Redis Pool — cache.py, monitoring.py, worker.py auf get_redis() umgestellt
B-RED: 5 direkte aioredis.from_url() Konstruktoren auf get_redis() umgestellt - cache.py: get_cache() delegiert auf get_redis(), _cache_redis Singleton entfernt - monitoring.py: check_redis() und check_worker() nutzen get_redis() - worker.py: _acquire_cron_lock() und _release_cron_lock() nutzen get_redis() - 0 verbleibende direkte aioredis.from_url() außerhalb auth.py B-RED-TEST: 8 Tests in test_redis_pool.py — alle grün - Singleton, get_cache delegation, SET/GET, parallel, reset, no-direct-from_url checks
This commit is contained in:
+4
-12
@@ -149,14 +149,10 @@ async def check_database() -> dict[str, Any]:
|
||||
async def check_redis() -> dict[str, Any]:
|
||||
"""Check Redis connectivity (async)."""
|
||||
try:
|
||||
import redis.asyncio as aioredis
|
||||
from app.core.auth import get_redis
|
||||
|
||||
from app.config import get_settings
|
||||
|
||||
settings = get_settings()
|
||||
r = aioredis.from_url(settings.redis_url, decode_responses=True)
|
||||
r = get_redis()
|
||||
pong = await r.ping()
|
||||
await r.aclose()
|
||||
if pong:
|
||||
return {"status": "up", "latency_ms": 0}
|
||||
return {"status": "down", "error": "Redis returned False for PING"}
|
||||
@@ -185,15 +181,11 @@ async def check_worker() -> dict[str, Any]:
|
||||
In test/dev mode this checks if Redis is available for the worker queue.
|
||||
"""
|
||||
try:
|
||||
import redis.asyncio as aioredis
|
||||
from app.core.auth import get_redis
|
||||
|
||||
from app.config import get_settings
|
||||
|
||||
settings = get_settings()
|
||||
r = aioredis.from_url(settings.redis_url, decode_responses=True)
|
||||
r = get_redis()
|
||||
# Check if arq queue key exists
|
||||
queue_length = await r.zcard("arq:queue")
|
||||
await r.aclose()
|
||||
return {"status": "up", "queue_length": queue_length}
|
||||
except Exception as e:
|
||||
return {"status": "down", "error": str(e)}
|
||||
|
||||
Reference in New Issue
Block a user