Skip to content

Commit

Permalink
fix(utils): update failed workflows duration using finished time (rea…
Browse files Browse the repository at this point in the history
…nahub#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.
  • Loading branch information
giuseppe-steduto committed Jan 18, 2024
1 parent 5d232af commit 3d83ea6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions reana-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"eslint-config-react-app": "^7.0.1",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-react": "^7.23.2",
"jest-date-mock": "^1.0.8",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.3",
"semantic-ui-less": "^2.4.1",
Expand Down
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
30 changes: 30 additions & 0 deletions reana-ui/src/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
formatSearch,
getDuration,
getMimeType,
parseWorkflowDates,
} from "~/util";
import { advanceTo, clear } from "jest-date-mock";

test.each([
["path/to/test.txt", "text/plain"],
Expand Down Expand Up @@ -56,3 +58,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,
},
};

advanceTo(new Date(2024, 0, 18, 8, 50, 0));
expect(parseWorkflowDates(workflow).duration).toEqual(duration);
clear();
},
);
5 changes: 5 additions & 0 deletions reana-ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6420,6 +6420,11 @@ jest-config@^27.5.1:
slash "^3.0.0"
strip-json-comments "^3.1.1"

jest-date-mock@^1.0.8:
version "1.0.8"
resolved "https://registry.yarnpkg.com/jest-date-mock/-/jest-date-mock-1.0.8.tgz#13468c0352c5a3614c6b356dbc6b88eb37d9e0b3"
integrity sha512-0Lyp+z9xvuNmLbK+5N6FOhSiBeux05Lp5bbveFBmYo40Aggl2wwxFoIrZ+rOWC8nDNcLeBoDd2miQdEDSf3iQw==

jest-diff@^27.5.1:
version "27.5.1"
resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-27.5.1.tgz#a07f5011ac9e6643cf8a95a462b7b1ecf6680def"
Expand Down

0 comments on commit 3d83ea6

Please sign in to comment.