-
Notifications
You must be signed in to change notification settings - Fork 13
feat: API pipeline run get has execution summary #97
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: ycq/api_pipeline_run_list_has_ended
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 |
|---|---|---|
|
|
@@ -130,11 +130,19 @@ def create( | |
| session.refresh(pipeline_run) | ||
| return PipelineRunResponse.from_db(pipeline_run) | ||
|
|
||
| def get(self, session: orm.Session, id: bts.IdType) -> PipelineRunResponse: | ||
| def get( | ||
| self, | ||
| session: orm.Session, | ||
| id: bts.IdType, | ||
| include_execution_stats: bool = False, | ||
| ) -> PipelineRunResponse: | ||
| pipeline_run = session.get(bts.PipelineRun, id) | ||
| if not pipeline_run: | ||
| raise ItemNotFoundError(f"Pipeline run {id} not found.") | ||
| return PipelineRunResponse.from_db(pipeline_run) | ||
| response = PipelineRunResponse.from_db(pipeline_run) | ||
| if include_execution_stats: | ||
|
Collaborator
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. Maybe we should expand the PipelineRun rather than the response? It provides more value to the rest of the codebase that might want to expand this information in other places later on. This suggestion implies moving the logic to the service layer (e.g. a PipelineRunsService rather than what is currently PipelineRunsApiService_Sql) and adding the field to the PipelineRun model rather than onto the response model.
Collaborator
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. PS: This relates to the fact that there might be opportunities to better organize our backend code in general. For example, orchestrator_sql.py has a lot going on. |
||
| response = self._populate_execution_stats(session=session, response=response) | ||
| return response | ||
|
|
||
| def terminate( | ||
| self, | ||
|
|
@@ -258,12 +266,7 @@ def create_pipeline_run_response( | |
| pipeline_name = component_spec.name | ||
| response.pipeline_name = pipeline_name | ||
| if include_execution_stats: | ||
| stats, summary = self._get_execution_stats_and_summary( | ||
| session=session, | ||
| root_execution_id=pipeline_run.root_execution_id, | ||
| ) | ||
| response.execution_status_stats = stats | ||
| response.execution_summary = summary | ||
| response = self._populate_execution_stats(session=session, response=response) | ||
| return response | ||
|
|
||
| return ListPipelineJobsResponse( | ||
|
|
@@ -274,6 +277,19 @@ def create_pipeline_run_response( | |
| next_page_token=next_page_token, | ||
| ) | ||
|
|
||
| def _populate_execution_stats( | ||
yuechao-qin marked this conversation as resolved.
Show resolved
Hide resolved
Collaborator
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. I would prefer to put general-purpose business logic on a separate class such as a PipelineRunsService rather than having functions like this in a module, and on a class, that is specifically tied to the http transport layer. |
||
| self, | ||
| session: orm.Session, | ||
| response: PipelineRunResponse, | ||
| ) -> PipelineRunResponse: | ||
| stats, summary = self._get_execution_stats_and_summary( | ||
| session=session, | ||
| root_execution_id=response.root_execution_id, | ||
| ) | ||
| response.execution_status_stats = stats | ||
| response.execution_summary = summary | ||
| return response | ||
|
|
||
| def _get_execution_stats_and_summary( | ||
| self, | ||
| session: orm.Session, | ||
|
|
||
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.
To each their own on this:
I prefer to use an
expandclass for these use cases, which is more extensible in the future.then using it as:
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.
You could totally say "pre-mature class" for just one expansion, but I find the consistency and readiness preferable over future refactors or inconsistency.