From 8b7bdf9034f2f44d4f5eb157171cf5dac01416f2 Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Tue, 26 Jun 2018 07:57:49 +0200 Subject: [PATCH] feat: added -disableWatchdog cli option --- src/coreHandler.ts | 11 +++++++---- src/index.ts | 9 +++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/coreHandler.ts b/src/coreHandler.ts index a095e07..89f3009 100644 --- a/src/coreHandler.ts +++ b/src/coreHandler.ts @@ -338,7 +338,8 @@ export class CoreMosDeviceHandler { } export interface CoreConfig { host: string, - port: number + port: number, + watchdog: boolean } /** * Represents a connection between mos-integration and Core @@ -353,6 +354,7 @@ export class CoreHandler { private _subscriptions: Array = [] private _isInitialized: boolean = false private _executedFunctions: {[id: string]: boolean} = {} + private _coreConfig?: CoreConfig constructor (logger: Winston.LoggerInstance, deviceOptions: DeviceConfig) { this.logger = logger @@ -360,7 +362,8 @@ export class CoreHandler { } init (config: CoreConfig): Promise { - this.logger.info('========') + // this.logger.info('========') + this._coreConfig = config this.core = new CoreConnection(this.getCoreConnectionOptions('MOS: Parent process', 'MosCoreParent', true)) this.core.onConnected(() => { @@ -427,7 +430,7 @@ export class CoreHandler { return _.extend(credentials, { deviceType: (parentProcess ? P.DeviceType.MOSDEVICE : P.DeviceType.OTHER), deviceName: name, - watchDog: true + watchDog: (this._coreConfig ? this._coreConfig.watchdog : true) }) } registerMosDevice (mosDevice: IMOSDevice, mosHandler: MosHandler): Promise { @@ -506,7 +509,7 @@ export class CoreHandler { executeFunction (cmd: PeripheralDeviceCommand, fcnObject: any) { if (cmd) { if (this._executedFunctions[cmd._id]) return // prevent it from running multiple times - this.logger.info(cmd.functionName, cmd.args) + this.logger.debug(cmd.functionName, cmd.args) this._executedFunctions[cmd._id] = true // console.log('executeFunction', cmd) let cb = (err: any, res?: any) => { diff --git a/src/index.ts b/src/index.ts index 4e4b34e..60c1181 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ let port: number = parseInt(process.env.CORE_PORT + '', 10) || 3000 let logPath: string = process.env.CORE_LOG || '' let deviceId: string = process.env.DEVICE_ID || '' let deviceToken: string = process.env.DEVICE_TOKEN || '' +let disableWatchdog: boolean = (process.env.DISABLE_WATCHDOG === '1') || false let debug: boolean = false logPath = logPath @@ -24,6 +25,8 @@ process.argv.forEach((val) => { deviceId = val } else if (prevProcessArg.match(/-token/i)) { deviceToken = val + } else if (val.match(/-disableWatchdog/i)) { + disableWatchdog = true } else if ((val + '').match(/-debug/i)) { debug = true } @@ -66,7 +69,7 @@ if (logPath) { level: 'verbose', handleExceptions: true, json: true, - stringify: (obj) => JSON.stringify(obj) // make single line + stringify: (obj: any) => JSON.stringify(obj) // make single line }) // Hijack console.log: // @ts-ignore @@ -90,6 +93,7 @@ process.on('warning', (e: any) => { logger.info('------------------------------------------------------------------') logger.info('Starting MOS Gateway') +if (disableWatchdog) logger.info('Watchdog is disabled!') // App config ----------------------------------------- let config: Config = { device: { @@ -98,7 +102,8 @@ let config: Config = { }, core: { host: host, - port: port + port: port, + watchdog: !disableWatchdog }, mos: { self: {