File size: 800 Bytes
bb7c9a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from loguru import logger
from pydantic import ConfigDict
from types import MappingProxyType
from typing import Collection, Mapping, Self

from ctp_slack_bot.core import ApplicationComponentBase, HealthReportingApplicationComponentBase


class ApplicationHealthService(ApplicationComponentBase):
    """
    Service for checking and reporting application health.
    """

    model_config = ConfigDict(frozen=True)

    services: list[HealthReportingApplicationComponentBase]

    async def get_health(self: Self) -> Mapping[str, bool]:
        return MappingProxyType({service.name: await service.is_healthy()
                                 for service
                                 in self.services})

    @property
    def name(self: Self) -> str:
        return "application_health_service"