diff --git a/reana_client/api/client.py b/reana_client/api/client.py index ba0d83bb..ecdfd5e4 100644 --- a/reana_client/api/client.py +++ b/reana_client/api/client.py @@ -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 diff --git a/reana_client/utils.py b/reana_client/utils.py index b8596bf2..16e2ac14 100644 --- a/reana_client/utils.py +++ b/reana_client/utils.py @@ -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. @@ -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()) diff --git a/reana_client/validation/environments.py b/reana_client/validation/environments.py index 878d9dda..0df707c8 100644 --- a/reana_client/validation/environments.py +++ b/reana_client/validation/environments.py @@ -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( ( diff --git a/tests/test_utils.py b/tests/test_utils.py index cbef171b..b982e9e6 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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": {