prepared skeleton for lab5
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""Условия готовности реплики и ограниченная проверка зависимостей."""
|
||||
|
||||
import asyncio
|
||||
|
||||
from redis.asyncio import Redis
|
||||
from sqlalchemy.ext.asyncio import AsyncEngine
|
||||
|
||||
from app.core.lifecycle import Lifecycle
|
||||
from app.errors.exceptions import unavailable
|
||||
from app.errors.handlers import operation_timeout
|
||||
from app.schemas.base import Health
|
||||
from app.storage.health import check_database, check_redis
|
||||
from app.storage.s3 import MinioStorage
|
||||
|
||||
|
||||
def liveness() -> Health:
|
||||
return Health(status='ok')
|
||||
|
||||
|
||||
async def readiness(
|
||||
engine: AsyncEngine, redis: Redis, storage: MinioStorage | None,
|
||||
lifecycle: Lifecycle, timeout_seconds: float,
|
||||
) -> Health:
|
||||
if lifecycle.draining:
|
||||
raise unavailable()
|
||||
checks = [check_database(engine), check_redis(redis)]
|
||||
if storage is not None:
|
||||
checks.append(storage.check_available())
|
||||
async with operation_timeout(timeout_seconds, unavailable()):
|
||||
dependencies = await asyncio.gather(*checks, return_exceptions=True)
|
||||
if not all(result is True for result in dependencies):
|
||||
raise unavailable()
|
||||
return Health(status='ok')
|
||||
Reference in New Issue
Block a user