Skip to content

Commit

Permalink
rest: add include_command flag to get_workflow endpoints
Browse files Browse the repository at this point in the history
Closes reanahub#486.
  • Loading branch information
giuseppe-steduto committed Nov 1, 2023
1 parent e8066e1 commit 6181379
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changes
=======

Version 0.9.2 (UNRELEASED)
--------------------------

- Changes ``get_workflow_status``, ``get_workflows`` endpoints to add a ``include_command`` optional parameter to show info about currently executing command.

Version 0.9.1 (2023-09-27)
--------------------------

Expand Down
14 changes: 14 additions & 0 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@
"required": false,
"type": "boolean"
},
{
"description": "Include current command information.",
"in": "query",
"name": "include_command",
"required": false,
"type": "boolean"
},
{
"description": "Optional analysis UUID or name to filter.",
"in": "query",
Expand Down Expand Up @@ -1011,6 +1018,13 @@
"name": "workflow_id_or_name",
"required": true,
"type": "string"
},
{
"description": "Include information about the current command.",
"in": "query",
"name": "include_command",
"required": false,
"type": "boolean"
}
],
"produces": [
Expand Down
9 changes: 7 additions & 2 deletions reana_workflow_controller/rest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,12 +690,16 @@ def get_most_recent_job_info(workflow_id: UUID) -> Dict[str, str]:
return current_job_commands


def get_workflow_progress(workflow: Workflow, include_progress: bool = False) -> Dict:
def get_workflow_progress(
workflow: Workflow, include_progress: bool = False, include_command: bool = False
) -> Dict:
"""Return workflow progress information.
:param workflow: The workflow to get progress information from.
:type: reana_db.models.Workflow instance.
:param include_progress: Whether or not to include the job progress information.
:param include_progress: Whether to include the job progress information or not.
:type: bool.
:param include_command: Whether to include the information about the current command or not.
:type: bool.
:return: Dictionary with workflow progress information.
Expand Down Expand Up @@ -732,6 +736,7 @@ def get_workflow_progress(workflow: Workflow, include_progress: bool = False) ->
job_id for job_id in progress[status]["job_ids"] if job_id
]

if include_command:
most_recent_job_info = get_most_recent_job_info(workflow.id_)
progress["current_command"] = most_recent_job_info.get("prettified_cmd")
progress["current_step_name"] = most_recent_job_info.get("current_job_name")
Expand Down
11 changes: 10 additions & 1 deletion reana_workflow_controller/rest/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
{
"include_progress": fields.Bool(),
"include_workspace_size": fields.Bool(),
"include_command": fields.Bool(),
"search": fields.String(missing=""),
"sort": fields.String(missing="desc"),
"status": fields.String(missing=""),
Expand Down Expand Up @@ -130,6 +131,11 @@ def get_workflows(args, paginate=None): # noqa
description: Include size information of the workspace.
required: false
type: boolean
- name: include_command
in: query
description: Include current command information.
required: false
type: boolean
- name: workflow_id_or_name
in: query
description: Optional analysis UUID or name to filter.
Expand Down Expand Up @@ -254,6 +260,7 @@ def get_workflows(args, paginate=None): # noqa
status_list: str = args["status"]
include_progress: bool = args.get("include_progress", verbose)
include_workspace_size: bool = args.get("include_workspace_size", verbose)
include_command: bool = args.get("include_command", verbose)
workflow_id_or_name: Optional[str] = args.get("workflow_id_or_name")

try:
Expand Down Expand Up @@ -301,7 +308,9 @@ def get_workflows(args, paginate=None): # noqa
"launcher_url": workflow.launcher_url,
"created": workflow.created.strftime(WORKFLOW_TIME_FORMAT),
"progress": get_workflow_progress(
workflow, include_progress=include_progress
workflow,
include_progress=include_progress,
include_command=include_command,
),
}
if type_ == "interactive" or verbose:
Expand Down
12 changes: 11 additions & 1 deletion reana_workflow_controller/rest/workflows_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ def get_workflow_status(workflow_id_or_name): # noqa
description: Required. Workflow UUID or name.
required: true
type: string
- name: include_command
in: query
description: Include information about the current command.
required: false
type: boolean
responses:
200:
description: >-
Expand Down Expand Up @@ -278,6 +283,9 @@ def get_workflow_status(workflow_id_or_name): # noqa

try:
user_uuid = request.args["user"]
include_command = json.loads(
request.args.get("include_command", "false").lower()
)
workflow = _get_workflow_with_uuid_or_name(workflow_id_or_name, user_uuid)
workflow_logs = build_workflow_logs(workflow)

Expand All @@ -288,7 +296,9 @@ def get_workflow_status(workflow_id_or_name): # noqa
"name": get_workflow_name(workflow),
"created": workflow.created.strftime(WORKFLOW_TIME_FORMAT),
"status": workflow.status.name,
"progress": get_workflow_progress(workflow, include_progress=True),
"progress": get_workflow_progress(
workflow, include_progress=True, include_command=include_command
),
"user": user_uuid,
"logs": json.dumps(workflow_logs),
}
Expand Down

0 comments on commit 6181379

Please sign in to comment.