Skip to content

Commit

Permalink
fix(status): correctly display duration of stopped workflows (reanahu…
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppe-steduto committed Jan 29, 2024
1 parent fa5b7c7 commit d3925f2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
6 changes: 3 additions & 3 deletions reana_client/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ def create_workflow_from_json(
reana_yaml["outputs"] = outputs
if workflow_file:
reana_yaml["workflow"]["file"] = workflow_file
reana_yaml["workflow"][
"specification"
] = load_workflow_spec_from_reana_yaml(reana_yaml, workspace_path)
reana_yaml["workflow"]["specification"] = (
load_workflow_spec_from_reana_yaml(reana_yaml, workspace_path)
)
else:
reana_yaml["workflow"]["specification"] = workflow_json
# The function below loads the input parameters into the reana_yaml dictionary
Expand Down
5 changes: 4 additions & 1 deletion reana_client/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2017, 2018, 2019, 2020, 2021, 2022 CERN.
# Copyright (C) 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand Down Expand Up @@ -146,12 +146,15 @@ def fromisoformat(date_string):
progress = workflow.get("progress", {})
run_started_at = progress.get("run_started_at")
run_finished_at = progress.get("run_finished_at")
run_stopped_at = progress.get("run_stopped_at")

duration = None
if run_started_at:
start_time = fromisoformat(run_started_at)
if run_finished_at:
end_time = fromisoformat(run_finished_at)
elif run_stopped_at:
end_time = fromisoformat(run_stopped_at)
else:
end_time = datetime.utcnow()
duration = round((end_time - start_time).total_seconds())
Expand Down
8 changes: 5 additions & 3 deletions reana_client/validation/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,11 @@ def validate_environment(self):
def _check_environment(environment):
image = "{}{}".format(
environment["image"],
":{}".format(environment["imagetag"])
if "imagetag" in environment
else "",
(
":{}".format(environment["imagetag"])
if "imagetag" in environment
else ""
),
)
k8s_uid = next(
(
Expand Down
11 changes: 11 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ def test_duration_finished_workflow():
assert get_workflow_duration(workflow) == 60 + 11


def test_duration_stopped_workflow():
workflow = {
"progress": {
"run_started_at": "2022-06-16T14:42:11",
"run_stopped_at": "2022-06-16T14:43:22",
"run_finished_at": None,
}
}
assert get_workflow_duration(workflow) == 60 + 11


def test_duration_running_workflow():
workflow = {
"progress": {
Expand Down

0 comments on commit d3925f2

Please sign in to comment.