Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Add failure states
Browse files Browse the repository at this point in the history
  • Loading branch information
ohltyler committed Apr 13, 2020
1 parent c8f7138 commit 80465d9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
6 changes: 5 additions & 1 deletion public/pages/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ export enum DETECTOR_STATES {
DISABLED = 'Disabled',
INIT = 'Initializing',
RUNNING = 'Running',
INIT_FAILURE = 'Initialization failure',
UNKNOWN_FAILURE = 'Unknown failure',
}

export enum DETECTOR_STATES_COLORS {
DISABLED = 'subdued',
INIT = 'warning',
INIT = '#0000cc',
RUNNING = 'success',
INIT_FAILURE = 'danger',
UNKNOWN_FAILURE = 'danger',
}

export const ALL_DETECTOR_STATES = [];
Expand Down
27 changes: 24 additions & 3 deletions server/routes/ad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,13 @@ const getDetectors = async (

const detectorStatePromises = allIds.map(async (id: string) => {
try {
const detectorStateResp = await callWithRequest(req, 'ad.detectorProfile', {
detectorId: id,
});
const detectorStateResp = await callWithRequest(
req,
'ad.detectorProfile',
{
detectorId: id,
}
);
return detectorStateResp;
} catch (err) {
console.log(
Expand All @@ -439,6 +443,23 @@ const getDetectors = async (
});
const detectorStates = await Promise.all(detectorStatePromises);

// check if there was any failures
detectorStates.forEach(detectorState => {
/*
If the error starts with 'Stopped detector', then an EndRunException was thrown.
All EndRunExceptions are related to initialization failures except for the
unknown prediction error which contains the message "We might have bugs".
*/
if (
detectorState.state == 'DISABLED' &&
detectorState.error.includes('Stopped detector')
) {
detectorState.state = detectorState.error.includes('We might have bugs')
? 'UNKNOWN_FAILURE'
: 'INIT_FAILURE';
}
});

// update the final detectors to include the detector state
finalDetectors.forEach((detector, i) => {
detector.curState = detectorStates[i].state;
Expand Down

0 comments on commit 80465d9

Please sign in to comment.