From 8dcd86bc2970b797875eccc1b7ec7942e6aaebde Mon Sep 17 00:00:00 2001 From: rozetko Date: Wed, 23 May 2018 21:20:12 +0300 Subject: [PATCH] Fix error when alert_anomalies.json doesn't exist --- server/src/services/alerts.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/src/services/alerts.ts b/server/src/services/alerts.ts index 07e85d3..0cf09f3 100644 --- a/server/src/services/alerts.ts +++ b/server/src/services/alerts.ts @@ -1,5 +1,6 @@ import { getJsonDataSync, writeJsonDataSync } from './json'; import * as path from 'path'; +import * as fs from 'fs'; import { AnomalyId } from './anomalyType'; import { ANOMALIES_PATH } from '../config'; import { runPredict } from './analytics'; @@ -7,6 +8,10 @@ import { sendNotification } from './notification'; import { getLabeledSegments } from './segments'; function getAlertsAnomalies() : AnomalyId[] { + let filename = path.join(ANOMALIES_PATH, `alerts_anomalies.json`); + if(!fs.existsSync(filename)) { + saveAlertsAnomalies([]); + } return getJsonDataSync(path.join(ANOMALIES_PATH, `alerts_anomalies.json`)); } @@ -52,7 +57,7 @@ async function alertsTick() { const alertTimeout = 60000; // ms const activeAlerts = new Set(); -// setTimeout(alertsTick, 5000); +setTimeout(alertsTick, 5000); export { getAlertsAnomalies, saveAlertsAnomalies }