🐛 fix(manager.py): handle None service in teardown loop to prevent potential errors

 feat(manager.py): add support for task manager service in the service manager initialization process
 feat(schema.py): add task manager service type to the ServiceType enum
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-09-01 17:22:14 -03:00
commit bd6655b0db
2 changed files with 10 additions and 2 deletions

View file

@ -1,9 +1,10 @@
from langflow.services.schema import ServiceType
from typing import TYPE_CHECKING, List, Optional
from typing import TYPE_CHECKING, Dict, List, Optional
from langflow.utils.logger import logger
if TYPE_CHECKING:
from langflow.services.factory import ServiceFactory
from langflow.services.base import Service
class ServiceManager:
@ -12,7 +13,7 @@ class ServiceManager:
"""
def __init__(self):
self.services = {}
self.services: Dict[str, "Service"] = {}
self.factories = {}
self.dependencies = {}
@ -85,6 +86,8 @@ class ServiceManager:
Teardown all the services.
"""
for service in self.services.values():
if service is None:
continue
logger.debug(f"Teardown service {service.name}")
service.teardown()
self.services = {}
@ -105,6 +108,7 @@ def initialize_services():
from langflow.services.settings import factory as settings_factory
from langflow.services.session import factory as session_manager_factory
from langflow.services.auth import factory as auth_factory
from langflow.services.task import factory as task_factory
service_manager.register_factory(settings_factory.SettingsManagerFactory())
service_manager.register_factory(
@ -124,6 +128,9 @@ def initialize_services():
session_manager_factory.SessionManagerFactory(),
dependencies=[ServiceType.CACHE_MANAGER],
)
service_manager.register_factory(
task_factory.TaskManagerFactory(),
)
# Test cache connection
service_manager.get(ServiceType.CACHE_MANAGER)

View file

@ -13,3 +13,4 @@ class ServiceType(str, Enum):
DATABASE_MANAGER = "database_manager"
CHAT_MANAGER = "chat_manager"
SESSION_MANAGER = "session_manager"
TASK_MANAGER = "task_manager"