Skip to content

Commit

Permalink
fix(progress): update failed workflows duration using finish time (#387)
Browse files Browse the repository at this point in the history
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 #386
  • Loading branch information
giuseppe-steduto committed Feb 12, 2024
1 parent f0edde6 commit 809fdc5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 4 additions & 1 deletion reana-ui/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,16 @@ export function getDuration(start, end) {
/**
* Parses workflows date info in a friendly way.
*/
function parseWorkflowDates(workflow) {
export function parseWorkflowDates(workflow) {
const createdMoment = moment.utc(workflow.created);
const startedMoment = moment.utc(workflow.progress.run_started_at);
const finishedMoment = moment.utc(workflow.progress.run_finished_at);
const stoppedMoment = moment.utc(workflow.progress.run_stopped_at);
// Mapping between workflow status and the end moment to use for calculating the duration
// If the workflow has not terminated yet (running, queued, pending), the endMoment should not be
// specified, and the current time will be used instead.
const endMomentStatusMapping = {
failed: finishedMoment,
finished: finishedMoment,
stopped: stoppedMoment,
deleted: finishedMoment.isValid() ? finishedMoment : stoppedMoment,
Expand Down
29 changes: 29 additions & 0 deletions reana-ui/src/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
formatSearch,
getDuration,
getMimeType,
parseWorkflowDates,
} from "~/util";

test.each([
Expand Down Expand Up @@ -56,3 +57,31 @@ test.each([
])("formatFileSize(%p) === %p", (fileSize, formattedFileSize) => {
expect(formatFileSize(fileSize)).toEqual(formattedFileSize);
});

test.each([
["finished", "15 min 0 sec", { run_finished_at: "2024-01-18T08:45:00" }],
["failed", "15 min 0 sec", { run_finished_at: "2024-01-18T08:45:00" }],
["stopped", "10 min 0 sec", { run_stopped_at: "2024-01-18T08:40:00" }],
["running", "20 min 0 sec", {}],
["queued", "20 min 0 sec", {}],
["pending", "20 min 0 sec", {}],
["created", "20 min 0 sec", {}],
])(
`parseWorkflowDates [status: %p], duration === %p`,
(status, duration, progress_override) => {
const workflow = {
status: status,
created: "2024-01-18T08:25:00",
progress: {
run_started_at: "2024-01-18T08:30:00",
run_stopped_at: null,
run_finished_at: null,
...progress_override,
},
};

jest.useFakeTimers();
jest.setSystemTime(new Date(2024, 0, 18, 8, 50, 0));
expect(parseWorkflowDates(workflow).duration).toEqual(duration);
},
);

0 comments on commit 809fdc5

Please sign in to comment.