Skip to content

Commit 160c25a

Browse files
committed
fix: Update temp flow cleanup to use async file operations
- Add explicit type hint for storage_service - Use async methods for file and directory existence checks - Improve error handling for file deletion during flow cleanup
1 parent de81c16 commit 160c25a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/backend/base/langflow/services/task/temp_flow_cleanup.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import asyncio
44
import contextlib
5+
from typing import TYPE_CHECKING
56

67
from loguru import logger
78
from sqlmodel import col, delete, select
@@ -11,6 +12,9 @@
1112
from langflow.services.database.models.vertex_builds.model import VertexBuildTable
1213
from langflow.services.deps import get_settings_service, get_storage_service, session_scope
1314

15+
if TYPE_CHECKING:
16+
from langflow.services.storage.service import StorageService
17+
1418

1519
async def cleanup_orphaned_records() -> None:
1620
"""Clean up all records that reference non-existent flows."""
@@ -39,7 +43,7 @@ async def cleanup_orphaned_records() -> None:
3943
await session.exec(delete(table).where(col(table.flow_id).in_(orphaned_flow_ids)))
4044

4145
# Clean up any associated storage files
42-
storage_service = get_storage_service()
46+
storage_service: StorageService = get_storage_service()
4347
for flow_id in orphaned_flow_ids:
4448
try:
4549
files = await storage_service.list_files(str(flow_id))
@@ -50,8 +54,8 @@ async def cleanup_orphaned_records() -> None:
5054
logger.error(f"Failed to delete file {file} for flow {flow_id}: {exc!s}")
5155
# Delete the flow directory after all files are deleted
5256
flow_dir = storage_service.data_dir / str(flow_id)
53-
if flow_dir.exists():
54-
flow_dir.rmdir()
57+
if await flow_dir.exists():
58+
await flow_dir.rmdir()
5559
except Exception as exc: # noqa: BLE001
5660
logger.error(f"Failed to list files for flow {flow_id}: {exc!s}")
5761

0 commit comments

Comments
 (0)