Skip to content

Commit

Permalink
Merge c2ce389 into f14d621
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidalgarcia committed Feb 7, 2020
2 parents f14d621 + c2ce389 commit 83d64cc
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 36 deletions.
3 changes: 3 additions & 0 deletions docs/openapi.json
Expand Up @@ -95,6 +95,9 @@
"name": {
"type": "string"
},
"progress": {
"type": "object"
},
"size": {
"type": "string"
},
Expand Down
37 changes: 37 additions & 0 deletions reana_workflow_controller/rest/utils.py
Expand Up @@ -451,3 +451,40 @@ def get_workspace_diff(workflow_a, workflow_b, brief=False, context_lines=5):
if not reana_fs.exists(workspace_b):
raise ValueError('Workspace of {} does not exist.'.format(
get_workflow_name(workflow_b)))


def get_workflow_progress(workflow):
"""Return workflow progress information.
:param workflow: The workflow to get progress information from.
:type: reana_db.models.Workflow instance.
:return: Dictionary with workflow progress information.
"""
current_job_progress = get_current_job_progress(workflow.id_)
cmd_and_step_name = {}
try:
_, cmd_and_step_name = current_job_progress.popitem()
except Exception:
pass
run_started_at = (workflow.run_started_at.
strftime(WORKFLOW_TIME_FORMAT)
if workflow.run_started_at else None)
run_finished_at = (workflow.run_finished_at.
strftime(WORKFLOW_TIME_FORMAT)
if workflow.run_finished_at else None)
initial_progress_status = {'total': 0, 'job_ids': []}
return {
'total': (workflow.job_progress.get('total') or
initial_progress_status),
'running': (workflow.job_progress.get('running') or
initial_progress_status),
'finished': (workflow.job_progress.get('finished') or
initial_progress_status),
'failed': (workflow.job_progress.get('failed') or
initial_progress_status),
'current_command': cmd_and_step_name.get('prettified_cmd'),
'current_step_name': cmd_and_step_name.get('current_job_name'),
'run_started_at': run_started_at,
'run_finished_at': run_finished_at
}
8 changes: 6 additions & 2 deletions reana_workflow_controller/rest/workflows.py
Expand Up @@ -25,8 +25,9 @@
REANAWorkflowNameError)
from reana_workflow_controller.rest.utils import (
get_specification_diff, get_workflow_name)
from reana_workflow_controller.rest.utils import \
create_workflow_workspace, get_workspace_diff
from reana_workflow_controller.rest.utils import (create_workflow_workspace,
get_workspace_diff,
get_workflow_progress)


START = 'start'
Expand Down Expand Up @@ -94,6 +95,8 @@ def get_workflows(): # noqa
type: string
created:
type: string
progress:
type: object
examples:
application/json:
[
Expand Down Expand Up @@ -168,6 +171,7 @@ def get_workflows(): # noqa
'user': user_uuid,
'created': workflow.created.
strftime(WORKFLOW_TIME_FORMAT),
'progress': get_workflow_progress(workflow),
'size': '-'}
if type == 'interactive':
if not workflow.interactive_session or \
Expand Down
36 changes: 2 additions & 34 deletions reana_workflow_controller/rest/workflows_status.py
Expand Up @@ -21,6 +21,7 @@
delete_workflow,
get_current_job_progress,
get_workflow_name,
get_workflow_progress,
start_workflow,
stop_workflow)

Expand Down Expand Up @@ -237,45 +238,12 @@ def get_workflow_status(workflow_id_or_name): # noqa
return jsonify(
{'message': 'User {} is not allowed to access workflow {}'
.format(user_uuid, workflow_id_or_name)}), 403

current_job_progress = get_current_job_progress(workflow.id_)
cmd_and_step_name = {}
try:
current_job_id, cmd_and_step_name = current_job_progress.\
popitem()
except Exception:
pass
run_started_at = None
if workflow.run_started_at:
run_started_at = workflow.run_started_at.\
strftime(WORKFLOW_TIME_FORMAT)
initial_progress_status = {'total': 0, 'job_ids': []}
progress = {'total':
workflow.job_progress.get('total') or
initial_progress_status,
'running':
workflow.job_progress.get('running') or
initial_progress_status,
'finished':
workflow.job_progress.get('finished') or
initial_progress_status,
'failed':
workflow.job_progress.get('failed') or
initial_progress_status,
'current_command':
cmd_and_step_name.get('prettified_cmd'),
'current_step_name':
cmd_and_step_name.get('current_job_name'),
'run_started_at':
run_started_at
}

return jsonify({'id': workflow.id_,
'name': get_workflow_name(workflow),
'created':
workflow.created.strftime(WORKFLOW_TIME_FORMAT),
'status': workflow.status.name,
'progress': progress,
'progress': get_workflow_progress(workflow),
'user': user_uuid,
'logs': json.dumps(workflow_logs)}), 200
except ValueError:
Expand Down
1 change: 1 addition & 0 deletions tests/test_views.py
Expand Up @@ -57,6 +57,7 @@ def test_get_workflows(app, session, default_user, cwl_workflow_with_name):
"status": workflow.status.name,
"user": str(workflow.owner_id),
"created": response_data[0]["created"],
"progress": response_data[0]["progress"],
"size": "-"
}
]
Expand Down

0 comments on commit 83d64cc

Please sign in to comment.