2024-08-09 12:41:23 +02:00
|
|
|
from anaxi.config import CosmosDBDatabaseConfig
|
|
|
|
|
from anaxi.constants import PATHS
|
|
|
|
|
from anaxi.cosmos_tools import create_cosmos_client_from_config
|
|
|
|
|
from anaxi.logging import get_anaxi_logger
|
2024-08-08 18:34:27 +02:00
|
|
|
|
2024-08-09 12:41:23 +02:00
|
|
|
logger = get_anaxi_logger(__name__)
|
2024-08-08 18:34:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def run_cosmos_db_healthcheck_process(cosmos_db_id: str) -> None:
|
|
|
|
|
|
2024-08-09 12:41:23 +02:00
|
|
|
logger.info("Reading Cosmos DB config file...")
|
|
|
|
|
cosmos_db_configs = CosmosDBDatabaseConfig.from_yaml(
|
|
|
|
|
PATHS.cosmos_db_config_file_path
|
2024-08-08 18:34:27 +02:00
|
|
|
)
|
2024-08-09 12:41:23 +02:00
|
|
|
logger.info(f"Found file with {len(cosmos_db_configs)} entries.")
|
|
|
|
|
try:
|
|
|
|
|
relevant_cosmos_db_config = cosmos_db_configs[cosmos_db_id]
|
|
|
|
|
except KeyError as e:
|
|
|
|
|
logger.error(
|
|
|
|
|
f"Couldn't find a config entry for database with id: {cosmos_db_id}"
|
|
|
|
|
)
|
|
|
|
|
raise e
|
|
|
|
|
|
|
|
|
|
logger.info("Creating client...")
|
|
|
|
|
cosmos_client = create_cosmos_client_from_config(relevant_cosmos_db_config)
|
|
|
|
|
logger.info("Client created.")
|
|
|
|
|
|
|
|
|
|
logger.info("Throwing a SELECT 1;")
|
|
|
|
|
response = cosmos_client.query_databases(query="SELECT 1")
|
|
|
|
|
logger.info(f"Response: {response.next()}")
|
|
|
|
|
|
|
|
|
|
return
|