Repository navigation
feat: add current_step and can_start to RunSerializer #2359
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -137,7 +137,13 @@ class Meta: | |||||||||||||
| "task_exitcode", | ||||||||||||||
| "task_output", | ||||||||||||||
| "log", | ||||||||||||||
| "current_step", | ||||||||||||||
| "execution_time", | ||||||||||||||
| "can_start", | ||||||||||||||
| ] | ||||||||||||||
| read_only_fields = [ | ||||||||||||||
| "current_step", | ||||||||||||||
| "can_start", | ||||||||||||||
| ] | ||||||||||||||
|
Comment on lines
+143
to
147
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1216,6 +1216,25 @@ def test_scanpipe_api_run_detail(self): | |
| self.assertEqual("", response.data["task_output"]) | ||
| self.assertIsNone(response.data["execution_time"]) | ||
| self.assertEqual(Run.Status.NOT_STARTED, response.data["status"]) | ||
| self.assertEqual("", response.data["current_step"]) | ||
| self.assertTrue(response.data["can_start"]) | ||
|
|
||
| run1.set_task_started(run1.pk) | ||
| run1.set_current_step("extract_archives") | ||
| response = self.csrf_client.get(url) | ||
| self.assertEqual(Run.Status.RUNNING, response.data["status"]) | ||
| self.assertEqual("extract_archives", response.data["current_step"]) | ||
| self.assertFalse(response.data["can_start"]) | ||
|
|
||
| run2 = self.project1.add_pipeline("analyze_docker_image") | ||
| url2 = reverse("run-detail", args=[run2.uuid]) | ||
| response2 = self.csrf_client.get(url2) | ||
| self.assertEqual(Run.Status.NOT_STARTED, response2.data["status"]) | ||
| self.assertFalse(response2.data["can_start"]) | ||
|
|
||
| run1.set_task_ended(exitcode=0) | ||
| response2 = self.csrf_client.get(url2) | ||
| self.assertTrue(response2.data["can_start"]) | ||
|
Comment on lines
+1229
to
+1237
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This tests the |
||
|
|
||
| @mock.patch("scanpipe.models.Run.execute_task_async") | ||
| def test_scanpipe_api_run_action_start_pipeline(self, mock_execute_task): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2499,7 +2499,9 @@ def test_scanpipe_webhook_subscription_model_get_payload(self): | |
| "task_exitcode": None, | ||
| "task_output": "", | ||
| "log": "", | ||
| "current_step": "", | ||
| "execution_time": None, | ||
| "can_start": True, | ||
|
Comment on lines
+2502
to
+2504
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both fields are excluded from the JSON results in |
||
| }, | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can_startruns a query for each not-started run (get_previous_runs()...exists()). SinceRunSerializeris also nested inProjectSerializer.runs, the project list endpoint now costs one extra query per queued run, up to the page size. TheassertNumQueriesintest_scanpipe_api_project_listdoes not catch it as those projects have no runs.The issue use case is polling
/api/runs/<uuid>/. What about excluding it from the nested runs:RunSerializer(many=True, read_only=True, exclude_fields=["can_start"])?