Refactor: handle error when retrieving messages from monitor service

This commit refactors the code in the `migrate_messages_from_monitor_service_to_database` function to handle errors that may occur when retrieving messages from the monitor service. If an exception is raised, the error is logged and the function returns `False`. This ensures that the migration process can continue even if there is an issue with retrieving the messages.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-06-27 14:36:02 -03:00
commit 67a34ffcb8

View file

@ -18,8 +18,12 @@ def migrate_messages_from_monitor_service_to_database(session: Session) -> bool:
from langflow.schema.message import Message
from langflow.services.database.models.message import MessageTable
monitor_service = get_monitor_service()
messages_df = monitor_service.get_messages()
try:
monitor_service = get_monitor_service()
messages_df = monitor_service.get_messages()
except Exception as e:
logger.error(f"Error retrieving messages from monitor service: {e}")
return False
if messages_df.empty:
logger.info("No messages to migrate.")