From 00e09cfe224ce2eb01c82d8eb8428e6a78630e29 Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Sun, 5 Aug 2018 18:51:44 +0300 Subject: [PATCH] metrics db path usage fix --- server/src/config.ts | 7 +------ server/src/index.ts | 2 +- server/src/services/data_service.ts | 2 +- server/src/services/process_service.ts | 18 ++++++++++++------ 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/server/src/config.ts b/server/src/config.ts index 75883f8..4f4ab34 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -10,16 +10,11 @@ export const ANALYTICS_PATH = path.join(__dirname, '../../analytics'); export const DATA_PATH = path.join(__dirname, '../../data'); -export const ANALYTIC_UNITS_DATABASE_PATH = path.join(DATA_PATH, 'analyticUnits.db'); +export const ANALYTIC_UNITS_DATABASE_PATH = path.join(DATA_PATH, 'analytic_units.db'); export const METRICS_DATABASE_PATH = path.join(DATA_PATH, 'metrics.db'); export const SEGMENTS_DATABASE_PATH = path.join(DATA_PATH, 'segments.db'); export const FILES_DATABASE_PATH = path.join(DATA_PATH, 'files.db'); -export const DATASETS_PATH = path.join(DATA_PATH, 'datasets'); -export const MODELS_PATH = path.join(DATA_PATH, 'models'); -export const METRICS_PATH = path.join(DATA_PATH, 'metrics'); -export const SEGMENTS_PATH = path.join(DATA_PATH, 'segments'); - export const HASTIC_PORT = getConfigField('HASTIC_PORT', '8000'); export const ZMQ_CONNECTION_STRING = getConfigField('ZMQ_CONNECTION_STRING', null); export const ZMQ_IPC_PATH = getConfigField('ZMQ_IPC_PATH', path.join('/tmp', 'hastic')); diff --git a/server/src/index.ts b/server/src/index.ts index ce04d94..2933d8a 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -1,6 +1,6 @@ import { router as anomaliesRouter } from './routes/analytic_units_router'; import { router as segmentsRouter } from './routes/segments_router'; -//import { router as alertsRouter } from './routes/alerts_router'; + import * as AnalyticsController from './controllers/analytics_controller'; diff --git a/server/src/services/data_service.ts b/server/src/services/data_service.ts index f1dea86..62a0555 100644 --- a/server/src/services/data_service.ts +++ b/server/src/services/data_service.ts @@ -120,5 +120,5 @@ checkDataFolders(); // TODO: it's better if models request db which we create if it`s needed db[Collection.ANALYTIC_UNITS] = new nedb({ filename: config.ANALYTIC_UNITS_DATABASE_PATH, autoload: true }); -db[Collection.METRICS] = new nedb({ filename: config.ANALYTIC_UNITS_DATABASE_PATH, autoload: true }); +db[Collection.METRICS] = new nedb({ filename: config.METRICS_DATABASE_PATH, autoload: true }); db[Collection.SEGMENTS] = new nedb({ filename: config.SEGMENTS_DATABASE_PATH, autoload: true }); diff --git a/server/src/services/process_service.ts b/server/src/services/process_service.ts index 1d9ce5b..b4bee36 100644 --- a/server/src/services/process_service.ts +++ b/server/src/services/process_service.ts @@ -12,7 +12,7 @@ export function registerExitHandler(callback: () => void) { exitHandlers.push(callback); } -function exitHandler(options, err) { +function exitHandler(options, err?) { if(exitHandled) { return; } @@ -24,15 +24,21 @@ function exitHandler(options, err) { process.exit(); } +function catchException(options, err) { + console.log('Server exception:'); + console.log(err); + exitHandler({ exit: true }); +} + //do something when app is closing -process.on('exit', exitHandler.bind(null,{cleanup:true})); +process.on('exit', exitHandler.bind(null, { cleanup:true })); //catches ctrl+c event -process.on('SIGINT', exitHandler.bind(null, {exit:true})); +process.on('SIGINT', exitHandler.bind(null, { exit:true })); // catches "kill pid" (for example: nodemon restart) -process.on('SIGUSR1', exitHandler.bind(null, {exit:true})); -process.on('SIGUSR2', exitHandler.bind(null, {exit:true})); +process.on('SIGUSR1', exitHandler.bind(null, { exit:true })); +process.on('SIGUSR2', exitHandler.bind(null, { exit:true })); //catches uncaught exceptions -process.on('uncaughtException', exitHandler.bind(null, {exit:true})); \ No newline at end of file +process.on('uncaughtException', catchException.bind(null, { exit:true })); \ No newline at end of file