Skip to content

Commit

Permalink
fix(status): display correct duration of stopped workflows (#701)
Browse files Browse the repository at this point in the history
Closes #699
  • Loading branch information
giuseppe-steduto committed Feb 1, 2024
1 parent 02dc830 commit b53def8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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
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 b53def8

Please sign in to comment.