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

Commit

Permalink
feat: added -disableWatchdog cli option
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Jun 26, 2018
1 parent b390c67 commit 8b7bdf9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/coreHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -353,14 +354,16 @@ export class CoreHandler {
private _subscriptions: Array<any> = []
private _isInitialized: boolean = false
private _executedFunctions: {[id: string]: boolean} = {}
private _coreConfig?: CoreConfig

constructor (logger: Winston.LoggerInstance, deviceOptions: DeviceConfig) {
this.logger = logger
this._deviceOptions = deviceOptions
}

init (config: CoreConfig): Promise<void> {
this.logger.info('========')
// this.logger.info('========')
this._coreConfig = config
this.core = new CoreConnection(this.getCoreConnectionOptions('MOS: Parent process', 'MosCoreParent', true))

this.core.onConnected(() => {
Expand Down Expand Up @@ -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<CoreMosDeviceHandler> {
Expand Down Expand Up @@ -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) => {
Expand Down
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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: {
Expand All @@ -98,7 +102,8 @@ let config: Config = {
},
core: {
host: host,
port: port
port: port,
watchdog: !disableWatchdog
},
mos: {
self: {
Expand Down

0 comments on commit 8b7bdf9

Please sign in to comment.