Timothy Jaeryang Baek 2 月之前
父節點
當前提交
d3b14ff827
共有 2 個文件被更改,包括 18 次插入0 次删除
  1. 16 0
      backend/open_webui/tasks.py
  2. 2 0
      backend/requirements.txt

+ 16 - 0
backend/open_webui/tasks.py

@@ -166,3 +166,19 @@ async def stop_task(redis, task_id: str):
         return {"status": True, "message": f"Task {task_id} successfully stopped."}
 
     return {"status": False, "message": f"Failed to stop task {task_id}."}
+
+
+async def stop_item_tasks(redis: Redis, item_id: str):
+    """
+    Stop all tasks associated with a specific item ID.
+    """
+    task_ids = await list_task_ids_by_item_id(redis, item_id)
+    if not task_ids:
+        return {"status": True, "message": f"No tasks found for item {item_id}."}
+
+    for task_id in task_ids:
+        result = await stop_task(redis, task_id)
+        if not result["status"]:
+            return result  # Return the first failure
+
+    return {"status": True, "message": f"All tasks for item {item_id} stopped."}

+ 2 - 0
backend/requirements.txt

@@ -31,6 +31,8 @@ boto3==1.35.53
 argon2-cffi==23.1.0
 APScheduler==3.10.4
 
+pycrdt==0.12.25
+
 RestrictedPython==8.0
 
 loguru==0.7.3