Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(utils): update failed workflows duration using finished time #387

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
},
);
2 changes: 1 addition & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ check_commitlint () {
}

check_shellcheck () {
find . -name "*.sh" -exec shellcheck {} \+
find . -name "*.sh" ! -path "./reana-ui/node_modules/*" -exec shellcheck {} \+
}

check_sphinx () {
Expand Down
Loading