Repository navigation
UN-4318 [FEAT] Show stuck executions and let owners abort running ones #2452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
kirtimanmishrazipstack
wants to merge
12
commits into
main
Choose a base branch
from
UN-4318-stuck-executions-abort
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,593
−244
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4bca922
UN-4318 [FEAT] List, count and abort stuck executions
kirtimanmishrazipstack fb22857
Merge remote-tracking branch 'origin/main' into UN-4318-stuck-executi…
kirtimanmishrazipstack 493fe01
UN-4318 [FEAT] Finish aborted runs properly and fix review findings
kirtimanmishrazipstack a9bf74f
UN-4318 Merge main into UN-4318-stuck-executions-abort
kirtimanmishrazipstack 6dc7e1e
UN-4318 [FEAT] Log an unknown status from the status check
kirtimanmishrazipstack a75bb86
UN-4318 [FEAT] Fix second review round: reporting, re-runs and crashe…
kirtimanmishrazipstack b441050
UN-4318 Merge main into UN-4318-stuck-executions-abort
kirtimanmishrazipstack 97ab0f0
UN-4318 Merge main into UN-4318-stuck-executions-abort
kirtimanmishrazipstack d742282
UN-4318 [FEAT] Fix third review round: stopped-run counts, failed bat…
kirtimanmishrazipstack cfeb9f4
UN-4318 [FEAT] Protect STOPPED on every run and match the failed batc…
kirtimanmishrazipstack e0006b5
UN-4318 [FEAT] Keep STOPPED against backend writes and leave a stoppe…
kirtimanmishrazipstack 71d701b
UN-4318 [FEAT] Report an aborted run once and keep its abort message
kirtimanmishrazipstack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| """API deployment calls report an aborted run as an error (UN-4318).""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from unittest.mock import patch | ||
|
|
||
| from account_v2.models import Organization | ||
| from django.core.files.uploadedfile import SimpleUploadedFile | ||
| from django.test import TestCase | ||
| from rest_framework.response import Response | ||
| from rest_framework.test import APIRequestFactory | ||
| from utils.user_context import UserContext | ||
| from workflow_manager.workflow_v2.dto import ExecutionResponse | ||
| from workflow_manager.workflow_v2.models.execution import WorkflowExecution | ||
| from workflow_manager.workflow_v2.models.workflow import Workflow | ||
|
|
||
| from api_v2.api_deployment_views import DeploymentExecution | ||
| from api_v2.models import APIDeployment, APIKey | ||
|
|
||
| ORG_ID = "org-aborted" | ||
|
|
||
|
|
||
| class SyncCallForAbortedRunTest(TestCase): | ||
| def setUp(self) -> None: | ||
| Organization.objects.create( | ||
| name=ORG_ID, display_name="Org", organization_id=ORG_ID | ||
| ) | ||
| UserContext.set_organization_identifier(ORG_ID) | ||
| self.workflow = Workflow.objects.create(workflow_name="wf", is_active=True) | ||
| self.api = APIDeployment.objects.create(api_name="api", workflow=self.workflow) | ||
| self.key = APIKey.objects.create(api=self.api) | ||
|
|
||
| def _post_with_status(self, execution_status: str) -> Response: | ||
| request = APIRequestFactory().post( | ||
| f"/deployment/api/{ORG_ID}/api/", | ||
| {"files": SimpleUploadedFile("doc.txt", b"hello")}, | ||
| format="multipart", | ||
| HTTP_AUTHORIZATION=f"Bearer {self.key.api_key}", | ||
| ) | ||
| with ( | ||
| patch( | ||
| "api_v2.api_deployment_views.APIDeploymentRateLimiter.check_and_acquire", | ||
| return_value=(True, {}), | ||
| ), | ||
| patch( | ||
| "api_v2.api_deployment_views.DeploymentHelper.execute_workflow", | ||
| return_value={"execution_status": execution_status}, | ||
| ), | ||
| ): | ||
| return DeploymentExecution.as_view()( | ||
| request, org_name=ORG_ID, api_name="api" | ||
| ) | ||
|
|
||
| def test_status_codes(self) -> None: | ||
| for execution_status, code in ( | ||
| ("STOPPED", 422), | ||
| ("ERROR", 422), | ||
| ("COMPLETED", 200), | ||
| ): | ||
| with self.subTest(execution_status=execution_status): | ||
| self.assertEqual( | ||
| self._post_with_status(execution_status).status_code, code | ||
| ) | ||
|
|
||
| def _get_stopped_result(self) -> Response: | ||
| item = { | ||
| "file": "doc.txt", | ||
| "metadata": {"workflow_id": "w", "highlight_data": [1]}, | ||
| "result": { | ||
| "output": {"a": 1}, | ||
| "metadata": {"inner": 1}, | ||
| "metrics": {"llm": 1}, | ||
| }, | ||
| } | ||
| execution = WorkflowExecution.objects.create( | ||
| workflow=self.workflow, | ||
| pipeline_id=self.api.id, | ||
| execution_mode=WorkflowExecution.Mode.QUEUE, | ||
| execution_method=WorkflowExecution.Method.DIRECT, | ||
| execution_type=WorkflowExecution.Type.COMPLETE, | ||
| status="STOPPED", | ||
| ) | ||
| stopped = ExecutionResponse( | ||
| workflow_id="w", | ||
| execution_id="e", | ||
| execution_status="STOPPED", | ||
| result=[item], | ||
| ) | ||
| request = APIRequestFactory().get( | ||
| f"/deployment/api/{ORG_ID}/api/", | ||
| {"execution_id": str(execution.id)}, | ||
| HTTP_AUTHORIZATION=f"Bearer {self.key.api_key}", | ||
| ) | ||
| helper = "api_v2.api_deployment_views.DeploymentHelper" | ||
| with ( | ||
| patch(f"{helper}.get_execution_status", return_value=stopped), | ||
| patch(f"{helper}._enrich_result_with_workflow_metadata"), | ||
| ): | ||
| return DeploymentExecution.as_view()( | ||
| request, org_name=ORG_ID, api_name="api" | ||
| ) | ||
|
|
||
| def test_get_filters_a_stopped_runs_results_like_post(self) -> None: | ||
| response = self._get_stopped_result() | ||
|
|
||
| self.assertEqual(response.status_code, 422) | ||
| item = response.data["message"][0] | ||
| self.assertNotIn("highlight_data", item["metadata"]) | ||
| self.assertNotIn("metrics", item["result"]) | ||
| self.assertNotIn("metadata", item["result"]) | ||
| self.assertEqual(item["result"]["output"], {"a": 1}) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.