🔧 fix(base.py): make Service class inherit from ABC to make it an abstract base class

 feat(manager.py): add debug log messages for service creation and update to improve debugging
 feat(manager.py): add teardown method to ServiceManager to teardown all services and clear state
 feat(manager.py): add teardown_services function to teardown all services and clear state
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-08-31 10:20:40 -03:00
commit 91ea879e50
2 changed files with 28 additions and 1 deletions

View file

@ -1,2 +1,8 @@
class Service:
from abc import ABC
class Service(ABC):
name: str
def teardown(self):
pass

View file

@ -1,5 +1,6 @@
from langflow.services.schema import ServiceType
from typing import TYPE_CHECKING, List, Optional
from langflow.utils.logger import logger
if TYPE_CHECKING:
from langflow.services.factory import ServiceFactory
@ -42,6 +43,7 @@ class ServiceManager:
"""
Create a new service given its name, handling dependencies.
"""
logger.debug(f"Create service {service_name}")
self._validate_service_creation(service_name)
# Create dependencies first
@ -74,9 +76,21 @@ class ServiceManager:
Update a service by its name.
"""
if service_name in self.services:
logger.debug(f"Update service {service_name}")
self.services.pop(service_name, None)
self.get(service_name)
def teardown(self):
"""
Teardown all the services.
"""
for service in self.services.values():
logger.debug(f"Teardown service {service.name}")
service.teardown()
self.services = {}
self.factories = {}
self.dependencies = {}
service_manager = ServiceManager()
@ -134,3 +148,10 @@ def initialize_session_manager():
session_manager_factory.SessionManagerFactory(),
dependencies=[ServiceType.CACHE_MANAGER],
)
def teardown_services():
"""
Teardown all the services.
"""
service_manager.teardown()