Skip to content

Commit

Permalink
[ML] Fix loading progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Aug 2, 2022
1 parent 514e5a7 commit 89148e3
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions x-pack/plugins/aiops/server/routes/explain_log_rate_spikes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ export const defineExplainLogRateSpikesRoute = (
logger
);

function endWithUpdatedLoadingState() {
push(
updateLoadingStateAction({
ccsWarning: false,
loaded: 1,
loadingState: i18n.translate(
'xpack.aiops.explainLogRateSpikes.loadingState.doneMessage',
{
defaultMessage: 'Done.',
}
),
})
);

end();
}

// Async IIFE to run the analysis while not blocking returning `responseWithHeaders`.
(async () => {
push(resetAction());
Expand All @@ -100,11 +117,7 @@ export const defineExplainLogRateSpikesRoute = (
return;
}

if (fieldCandidates.length > 0) {
loaded += LOADED_FIELD_CANDIDATES;
} else {
loaded = 1;
}
loaded += LOADED_FIELD_CANDIDATES;

push(
updateLoadingStateAction({
Expand All @@ -123,7 +136,9 @@ export const defineExplainLogRateSpikesRoute = (
})
);

if (shouldStop || fieldCandidates.length === 0) {
if (fieldCandidates.length === 0) {
endWithUpdatedLoadingState();
} else if (shouldStop) {
end();
return;
}
Expand Down Expand Up @@ -179,7 +194,7 @@ export const defineExplainLogRateSpikesRoute = (
}

if (changePoints?.length === 0) {
end();
endWithUpdatedLoadingState();
return;
}

Expand Down Expand Up @@ -274,20 +289,7 @@ export const defineExplainLogRateSpikesRoute = (
});
}

push(
updateLoadingStateAction({
ccsWarning: false,
loaded: 1,
loadingState: i18n.translate(
'xpack.aiops.explainLogRateSpikes.loadingState.doneMessage',
{
defaultMessage: 'Done.',
}
),
})
);

end();
endWithUpdatedLoadingState();
})();

return response.ok(responseWithHeaders);
Expand Down

0 comments on commit 89148e3

Please sign in to comment.