Spaces:
Sleeping
Sleeping
Michael Hu
commited on
Commit
·
d2f68d2
1
Parent(s):
38ac604
add more logs
Browse files
src/infrastructure/config/container_setup.py
CHANGED
|
@@ -261,21 +261,34 @@ def create_configured_container(config_file: Optional[str] = None) -> Dependency
|
|
| 261 |
DependencyContainer: Fully configured container
|
| 262 |
"""
|
| 263 |
try:
|
|
|
|
|
|
|
| 264 |
# Setup container
|
|
|
|
| 265 |
container = setup_container(config_file)
|
|
|
|
| 266 |
|
| 267 |
# Configure logging
|
|
|
|
| 268 |
config = container.resolve(AppConfig)
|
| 269 |
configure_logging(config)
|
|
|
|
| 270 |
|
| 271 |
# Validate container setup
|
| 272 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
|
| 274 |
logger.info("Application container created and configured successfully")
|
| 275 |
return container
|
| 276 |
|
| 277 |
except Exception as e:
|
| 278 |
-
logger.error(f"Failed to create configured container: {e}")
|
| 279 |
raise
|
| 280 |
|
| 281 |
|
|
@@ -306,23 +319,41 @@ def _validate_container_setup(container: DependencyContainer) -> None:
|
|
| 306 |
|
| 307 |
missing_services = []
|
| 308 |
|
|
|
|
| 309 |
for service_type in required_services:
|
|
|
|
| 310 |
if not container.is_registered(service_type):
|
| 311 |
missing_services.append(service_type.__name__)
|
|
|
|
|
|
|
|
|
|
| 312 |
|
| 313 |
if missing_services:
|
| 314 |
-
|
|
|
|
|
|
|
| 315 |
|
| 316 |
# Test service resolution
|
|
|
|
| 317 |
try:
|
|
|
|
| 318 |
config = container.resolve(AppConfig)
|
|
|
|
|
|
|
|
|
|
| 319 |
app_service = container.resolve(AudioProcessingApplicationService)
|
|
|
|
|
|
|
|
|
|
| 320 |
config_service = container.resolve(ConfigurationApplicationService)
|
|
|
|
| 321 |
|
| 322 |
-
logger.
|
| 323 |
|
| 324 |
except Exception as e:
|
| 325 |
-
|
|
|
|
|
|
|
| 326 |
|
| 327 |
|
| 328 |
def get_service_registry_info(container: DependencyContainer) -> dict:
|
|
|
|
| 261 |
DependencyContainer: Fully configured container
|
| 262 |
"""
|
| 263 |
try:
|
| 264 |
+
logger.info("Creating configured container...")
|
| 265 |
+
|
| 266 |
# Setup container
|
| 267 |
+
logger.info("Setting up container...")
|
| 268 |
container = setup_container(config_file)
|
| 269 |
+
logger.info("Container setup completed")
|
| 270 |
|
| 271 |
# Configure logging
|
| 272 |
+
logger.info("Configuring logging...")
|
| 273 |
config = container.resolve(AppConfig)
|
| 274 |
configure_logging(config)
|
| 275 |
+
logger.info("Logging configuration completed")
|
| 276 |
|
| 277 |
# Validate container setup
|
| 278 |
+
logger.info("Starting container validation...")
|
| 279 |
+
try:
|
| 280 |
+
_validate_container_setup(container)
|
| 281 |
+
logger.info("Container validation completed")
|
| 282 |
+
except Exception as validation_error:
|
| 283 |
+
logger.error(f"Container validation failed: {validation_error}", exc_info=True)
|
| 284 |
+
# For now, let's continue even if validation fails to see if the app works
|
| 285 |
+
logger.warning("Continuing despite validation failure...")
|
| 286 |
|
| 287 |
logger.info("Application container created and configured successfully")
|
| 288 |
return container
|
| 289 |
|
| 290 |
except Exception as e:
|
| 291 |
+
logger.error(f"Failed to create configured container: {e}", exc_info=True)
|
| 292 |
raise
|
| 293 |
|
| 294 |
|
|
|
|
| 319 |
|
| 320 |
missing_services = []
|
| 321 |
|
| 322 |
+
logger.info("Checking service registrations...")
|
| 323 |
for service_type in required_services:
|
| 324 |
+
logger.debug(f"Checking registration for: {service_type.__name__}")
|
| 325 |
if not container.is_registered(service_type):
|
| 326 |
missing_services.append(service_type.__name__)
|
| 327 |
+
logger.error(f"Service not registered: {service_type.__name__}")
|
| 328 |
+
else:
|
| 329 |
+
logger.debug(f"Service registered: {service_type.__name__}")
|
| 330 |
|
| 331 |
if missing_services:
|
| 332 |
+
error_msg = f"Container validation failed. Missing services: {missing_services}"
|
| 333 |
+
logger.error(error_msg)
|
| 334 |
+
raise RuntimeError(error_msg)
|
| 335 |
|
| 336 |
# Test service resolution
|
| 337 |
+
logger.info("Testing service resolution...")
|
| 338 |
try:
|
| 339 |
+
logger.debug("Resolving AppConfig...")
|
| 340 |
config = container.resolve(AppConfig)
|
| 341 |
+
logger.debug("AppConfig resolved successfully")
|
| 342 |
+
|
| 343 |
+
logger.debug("Resolving AudioProcessingApplicationService...")
|
| 344 |
app_service = container.resolve(AudioProcessingApplicationService)
|
| 345 |
+
logger.debug("AudioProcessingApplicationService resolved successfully")
|
| 346 |
+
|
| 347 |
+
logger.debug("Resolving ConfigurationApplicationService...")
|
| 348 |
config_service = container.resolve(ConfigurationApplicationService)
|
| 349 |
+
logger.debug("ConfigurationApplicationService resolved successfully")
|
| 350 |
|
| 351 |
+
logger.info("Container validation successful")
|
| 352 |
|
| 353 |
except Exception as e:
|
| 354 |
+
error_msg = f"Container validation failed during service resolution: {e}"
|
| 355 |
+
logger.error(error_msg, exc_info=True)
|
| 356 |
+
raise RuntimeError(error_msg)
|
| 357 |
|
| 358 |
|
| 359 |
def get_service_registry_info(container: DependencyContainer) -> dict:
|