Skip to content

Commit 12a3563

Browse files
fix(utils): update failed workflows duration using finished time (reanahub#387)
Fix the way in which the duration of failed workflows is calculated, to use the time at which the run was finished rather than the current time. Closes reanahub#386.
1 parent 8ad4afd commit 12a3563

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

reana-ui/src/util.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,16 @@ export function getDuration(start, end) {
156156
/**
157157
* Parses workflows date info in a friendly way.
158158
*/
159-
function parseWorkflowDates(workflow) {
159+
export function parseWorkflowDates(workflow) {
160160
const createdMoment = moment.utc(workflow.created);
161161
const startedMoment = moment.utc(workflow.progress.run_started_at);
162162
const finishedMoment = moment.utc(workflow.progress.run_finished_at);
163163
const stoppedMoment = moment.utc(workflow.progress.run_stopped_at);
164164
// Mapping between workflow status and the end moment to use for calculating the duration
165+
// If the workflow has not terminated yet (running, queued, pending), the endMoment should not be
166+
// specified, and the current time will be used instead.
165167
const endMomentStatusMapping = {
168+
failed: finishedMoment,
166169
finished: finishedMoment,
167170
stopped: stoppedMoment,
168171
deleted: finishedMoment.isValid() ? finishedMoment : stoppedMoment,

reana-ui/src/util.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
formatSearch,
55
getDuration,
66
getMimeType,
7+
parseWorkflowDates,
78
} from "~/util";
89

910
test.each([
@@ -56,3 +57,31 @@ test.each([
5657
])("formatFileSize(%p) === %p", (fileSize, formattedFileSize) => {
5758
expect(formatFileSize(fileSize)).toEqual(formattedFileSize);
5859
});
60+
61+
test.each([
62+
["finished", "15 min 0 sec", { run_finished_at: "2024-01-18T08:45:00" }],
63+
["failed", "15 min 0 sec", { run_finished_at: "2024-01-18T08:45:00" }],
64+
["stopped", "10 min 0 sec", { run_stopped_at: "2024-01-18T08:40:00" }],
65+
["running", "20 min 0 sec", {}],
66+
["queued", "20 min 0 sec", {}],
67+
["pending", "20 min 0 sec", {}],
68+
["created", "20 min 0 sec", {}],
69+
])(
70+
`parseWorkflowDates [status: %p], duration === %p`,
71+
(status, duration, progress_override) => {
72+
const workflow = {
73+
status: status,
74+
created: "2024-01-18T08:25:00",
75+
progress: {
76+
run_started_at: "2024-01-18T08:30:00",
77+
run_stopped_at: null,
78+
run_finished_at: null,
79+
...progress_override,
80+
},
81+
};
82+
83+
jest.useFakeTimers();
84+
jest.setSystemTime(new Date(2024, 0, 18, 8, 50, 0));
85+
expect(parseWorkflowDates(workflow).duration).toEqual(duration);
86+
},
87+
);

0 commit comments

Comments
 (0)