Skip to content

Commit 67a0aa4

Browse files
committed
feat: Cross thread cancellation of workflow
1 parent 488346b commit 67a0aa4

1 file changed

Lines changed: 3 additions & 9 deletions

File tree

‎apps/application/views/application_chat.py‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from common.log.log import _get_ip_address
3333
from common.result import result
3434
from common.utils.common import query_params_to_single_dict
35+
from common.bus import emit
3536

3637

3738
def get_application_operation_object(application_id):
@@ -240,15 +241,8 @@ class CancelWorkflowView(APIView):
240241
RoleConstants.WORKSPACE_MANAGE.get_workspace_role(),
241242
)
242243
def post(self, request: Request, workspace_id: str, application_id: str, chat_id: str):
243-
from application.workflow.workflow_run_registry import WorkflowRunRegistry, CancelResult
244-
245-
result_enum = WorkflowRunRegistry.cancel_by_chat_id(chat_id)
246-
if result_enum == CancelResult.CANCELLED:
247-
return result.success({"status": "cancelled", "chat_id": chat_id})
248-
elif result_enum == CancelResult.NOT_FOUND:
249-
return result.success({"status": "not_found", "chat_id": chat_id})
250-
else:
251-
return result.error(_("Failed to cancel workflow"))
244+
emit("cancel_chat", {"chat_id": str(chat_id)})
245+
return result.success({"status": "cancelled", "chat_id": chat_id})
252246

253247

254248
class ResumeStreamView(APIView):

0 commit comments

Comments
 (0)