🐛 fix(manager.py): catch and log exceptions when tearing down services to prevent silent failures

🐛 fix(utils.py): catch and log exceptions when tearing down services and superuser to prevent silent failures
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-10-04 12:49:10 -03:00
commit f9d9adf60b
2 changed files with 7 additions and 7 deletions

View file

@ -90,7 +90,10 @@ class ServiceManager:
if service is None:
continue
logger.debug(f"Teardown service {service.name}")
service.teardown()
try:
service.teardown()
except Exception as exc:
logger.exception(exc)
self.services = {}
self.factories = {}
self.dependencies = {}
@ -150,9 +153,3 @@ def initialize_session_service():
dependencies=[ServiceType.CACHE_SERVICE],
)
def teardown_services():
"""
Teardown all the services.
"""
service_manager.teardown()

View file

@ -153,6 +153,9 @@ def teardown_services():
"""
try:
teardown_superuser(get_settings_service(), next(get_session()))
except Exception as exc:
logger.exception(exc)
try:
service_manager.teardown()
except Exception as exc:
logger.exception(exc)