Skip to content

Commit cef3236

Browse files
committed
wip: hotStandby - implement hotStandby error handling and messages
1 parent e7f59e2 commit cef3236

File tree

3 files changed

+40
-19
lines changed

3 files changed

+40
-19
lines changed

packages/mos-gateway/src/CoreMosDeviceHandler.ts

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ export class CoreMosDeviceHandler {
7575
private _pendingStoryItemChanges: Array<IStoryItemChange> = []
7676
private _pendingChangeTimeout: number = 60 * 1000
7777
private mosTypes: MosTypes
78+
private _hotStandby: boolean
7879

7980
private _messageQueue: Queue
8081

81-
constructor(parent: CoreHandler, mosDevice: IMOSDevice, mosHandler: MosHandler) {
82+
constructor(parent: CoreHandler, mosDevice: IMOSDevice, mosHandler: MosHandler, hotStandby: boolean) {
8283
this._coreParentHandler = parent
8384
this._mosDevice = mosDevice
8485
this._mosHandler = mosHandler
86+
this._hotStandby = hotStandby
8587

8688
this._messageQueue = new Queue()
8789

@@ -138,25 +140,39 @@ export class CoreMosDeviceHandler {
138140
let statusCode: StatusCode
139141
const messages: Array<string> = []
140142

141-
if (connectionStatus.PrimaryConnected) {
142-
if (connectionStatus.SecondaryConnected || !this._mosDevice.idSecondary) {
143+
if (this._hotStandby) {
144+
if (connectionStatus.PrimaryConnected) {
143145
statusCode = StatusCode.GOOD
144146
} else {
145-
statusCode = StatusCode.WARNING_MINOR
147+
if (connectionStatus.SecondaryConnected) {
148+
statusCode = StatusCode.GOOD
149+
messages.push(connectionStatus.SecondaryStatus || 'Running NRCS on hot standby')
150+
} else {
151+
statusCode = StatusCode.BAD
152+
messages.push(connectionStatus.SecondaryStatus || 'Primary and hot standby are not connected')
153+
}
146154
}
147155
} else {
148-
if (connectionStatus.SecondaryConnected) {
149-
statusCode = StatusCode.WARNING_MAJOR
156+
if (connectionStatus.PrimaryConnected) {
157+
if (connectionStatus.SecondaryConnected || !this._mosDevice.idSecondary) {
158+
statusCode = StatusCode.GOOD
159+
} else {
160+
statusCode = StatusCode.WARNING_MINOR
161+
}
150162
} else {
151-
statusCode = StatusCode.BAD
163+
if (connectionStatus.SecondaryConnected) {
164+
statusCode = StatusCode.WARNING_MAJOR
165+
} else {
166+
statusCode = StatusCode.BAD
167+
}
152168
}
153-
}
154169

155-
if (!connectionStatus.PrimaryConnected) {
156-
messages.push(connectionStatus.PrimaryStatus || 'Primary not connected')
157-
}
158-
if (this._mosDevice.idSecondary && !connectionStatus.SecondaryConnected) {
159-
messages.push(connectionStatus.SecondaryStatus || 'Fallback not connected')
170+
if (!connectionStatus.PrimaryConnected) {
171+
messages.push(connectionStatus.PrimaryStatus || 'Primary not connected')
172+
}
173+
if (this._mosDevice.idSecondary && !connectionStatus.SecondaryConnected) {
174+
messages.push(connectionStatus.SecondaryStatus || 'Fallback not connected')
175+
}
160176
}
161177

162178
this.core

packages/mos-gateway/src/coreHandler.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,13 @@ export class CoreHandler {
142142

143143
return options
144144
}
145-
async registerMosDevice(mosDevice: IMOSDevice, mosHandler: MosHandler): Promise<CoreMosDeviceHandler> {
145+
async registerMosDevice(
146+
mosDevice: IMOSDevice,
147+
mosHandler: MosHandler,
148+
hotStandby: boolean
149+
): Promise<CoreMosDeviceHandler> {
146150
this.logger.info('registerMosDevice -------------')
147-
const coreMos = new CoreMosDeviceHandler(this, mosDevice, mosHandler)
151+
const coreMos = new CoreMosDeviceHandler(this, mosDevice, mosHandler, hotStandby)
148152

149153
this._coreMosHandlers.push(coreMos)
150154
return coreMos.init().then(() => {

packages/mos-gateway/src/mosHandler.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,15 @@ export class MosHandler {
5959
private _logger: Winston.Logger
6060
private _disposed = false
6161
private _settings?: MosGatewayConfig
62+
private _hotStandby: boolean
6263
private _coreHandler: CoreHandler | undefined
6364
private _observers: Array<Observer<any>> = []
6465
private _triggerupdateDevicesTimeout: any = null
6566
private mosTypes: MosTypes
6667

6768
constructor(logger: Winston.Logger) {
6869
this._logger = logger
70+
this._hotStandby = false
6971
this.mosTypes = getMosTypes(this.strict) // temporary, another will be set upon init()
7072
}
7173
async init(config: MosConfig, coreHandler: CoreHandler): Promise<void> {
@@ -101,7 +103,7 @@ export class MosHandler {
101103

102104
this.mosTypes = getMosTypes(this.strict)
103105

104-
await this._initMosConnection()
106+
await this._updateDevices()
105107

106108
if (!this._coreHandler) throw Error('_coreHandler is undefined!')
107109
this._coreHandler.onConnected(() => {
@@ -110,8 +112,6 @@ export class MosHandler {
110112
this.sendStatusOfAllMosDevices()
111113
})
112114
this.setupObservers()
113-
114-
return this._updateDevices()
115115
}
116116
async dispose(): Promise<void> {
117117
this._disposed = true
@@ -243,7 +243,7 @@ export class MosHandler {
243243

244244
if (!this._coreHandler) throw Error('_coreHandler is undefined!')
245245

246-
const coreMosHandler = await this._coreHandler.registerMosDevice(mosDevice, this)
246+
const coreMosHandler = await this._coreHandler.registerMosDevice(mosDevice, this, this._hotStandby)
247247
// this._logger.info('mosDevice registered -------------')
248248
// Setup message flow between the devices:
249249

@@ -420,6 +420,7 @@ export class MosHandler {
420420
for (const [deviceId, device] of Object.entries<{ options: MosDeviceConfig }>(devices)) {
421421
if (device) {
422422
if (device.options.secondary) {
423+
this._hotStandby = device.options.secondary?.hotStandby || false
423424
// If the host isn't set, don't use secondary:
424425
if (!device.options.secondary.host || !device.options.secondary.id)
425426
delete device.options.secondary

0 commit comments

Comments
 (0)