From 80465d9d43ce13507adcdc4e548d81f845e1ebd5 Mon Sep 17 00:00:00 2001 From: Tyler Ohlsen Date: Mon, 13 Apr 2020 11:23:19 -0700 Subject: [PATCH] Add failure states --- public/pages/utils/constants.ts | 6 +++++- server/routes/ad.ts | 27 ++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/public/pages/utils/constants.ts b/public/pages/utils/constants.ts index ccccf180..7915063d 100644 --- a/public/pages/utils/constants.ts +++ b/public/pages/utils/constants.ts @@ -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 = []; diff --git a/server/routes/ad.ts b/server/routes/ad.ts index 92e05d4e..1f194b6e 100644 --- a/server/routes/ad.ts +++ b/server/routes/ad.ts @@ -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( @@ -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;