🐛 fix(celery_app.py): ignore type error for Celery import to avoid linting issues

🐛 fix(base.py): ignore type error for AsyncResult import to avoid linting issues

🐛 fix(worker.py): ignore type error for SoftTimeLimitExceeded import to avoid linting issues
✨ feat(worker.py): add conditional clearing of session cache based on clear_cache flag to improve performance
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-09-05 15:35:14 -03:00
commit 0d9d4856fb
3 changed files with 5 additions and 5 deletions

View file

@ -1,4 +1,4 @@
from celery import Celery from celery import Celery # type: ignore
def make_celery(app_name: str): def make_celery(app_name: str):

View file

@ -76,7 +76,7 @@ class Vertex:
def get_task(self): def get_task(self):
# using the task_id, get the task from celery # using the task_id, get the task from celery
# and return it # and return it
from celery.result import AsyncResult from celery.result import AsyncResult # type: ignore
return AsyncResult(self.task_id) return AsyncResult(self.task_id)

View file

@ -1,9 +1,8 @@
from langflow.core.celery_app import celery_app from langflow.core.celery_app import celery_app
from typing import Any, Dict, Optional, Tuple from typing import Any, Dict, Optional, Tuple
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from celery.exceptions import SoftTimeLimitExceeded from celery.exceptions import SoftTimeLimitExceeded # type: ignore
from langflow.processing.process import ( from langflow.processing.process import (
clear_caches_if_needed,
generate_result, generate_result,
process_inputs, process_inputs,
) )
@ -42,8 +41,9 @@ def process_graph_cached_task(
session_id=None, session_id=None,
) -> Tuple[Any, str]: ) -> Tuple[Any, str]:
initialize_session_manager() initialize_session_manager()
clear_caches_if_needed(clear_cache)
session_manager = get_session_manager() session_manager = get_session_manager()
if clear_cache:
session_manager.clear_session(session_id)
# Load the graph using SessionManager # Load the graph using SessionManager
langchain_object, artifacts = session_manager.load_session(session_id, data_graph) langchain_object, artifacts = session_manager.load_session(session_id, data_graph)
processed_inputs = process_inputs(inputs, artifacts) processed_inputs = process_inputs(inputs, artifacts)