40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from app.core.logging_config import get_logger, setup_logging
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
def on_startup() -> None:
|
|
"""Application startup event handler."""
|
|
setup_logging()
|
|
logger.info("application_starting", phase="startup")
|
|
|
|
# Ensure storage directories exist
|
|
from app.storage.provider import get_storage_provider
|
|
try:
|
|
get_storage_provider()
|
|
logger.info("storage_initialized")
|
|
except Exception as e:
|
|
logger.error("storage_init_failed", error=str(e))
|
|
|
|
# Verify database connection
|
|
from app.core.database import check_database_connection
|
|
if check_database_connection():
|
|
logger.info("database_connected")
|
|
else:
|
|
logger.error("database_connection_failed")
|
|
|
|
logger.info("application_started", phase="startup_complete")
|
|
|
|
|
|
def on_shutdown() -> None:
|
|
"""Application shutdown event handler."""
|
|
logger.info("application_shutting_down", phase="shutdown")
|
|
|
|
# Cleanup resources
|
|
from app.core.database import engine
|
|
engine.dispose()
|
|
|
|
logger.info("application_stopped", phase="shutdown_complete")
|