From 9ed0b51861de36691064456c520d1763d7c623e8 Mon Sep 17 00:00:00 2001 From: dcaputo-harmoni <65166251+dcaputo-harmoni@users.noreply.github.com> Date: Sun, 14 May 2023 08:47:34 -0400 Subject: [PATCH 1/2] fixes #1349 --- src/features/device-heartbeat/index.ts | 50 +++++++++++++------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/features/device-heartbeat/index.ts b/src/features/device-heartbeat/index.ts index c7658f86c..a7220fc5b 100644 --- a/src/features/device-heartbeat/index.ts +++ b/src/features/device-heartbeat/index.ts @@ -298,30 +298,32 @@ export class DeviceOnlineStateManager extends EventEmitter<{ }; // raise and event for the state change... - switch (nextState) { - case DeviceOnlineStates.Timeout: - await this.updateDeviceModel( - deviceId, - DeviceOnlineStates.Timeout, - ); - this.scheduleChangeOfStateForDevice( - deviceId, - await this.getDeviceOnlineState(deviceId), - DeviceOnlineStates.Timeout, - DeviceOnlineStates.Offline, - API_HEARTBEAT_STATE_TIMEOUT_SECONDS, // put the device into a timeout state if it misses it's scheduled heartbeat window... then mark as offline - ); - break; - case DeviceOnlineStates.Offline: - await this.updateDeviceModel( - deviceId, - DeviceOnlineStates.Offline, - ); - break; - default: - throw new Error( - `An unexpected value was encountered for the target device state: ${nextState}`, - ); + if (deviceId) { + switch (nextState) { + case DeviceOnlineStates.Timeout: + await this.updateDeviceModel( + deviceId, + DeviceOnlineStates.Timeout, + ); + this.scheduleChangeOfStateForDevice( + deviceId, + await this.getDeviceOnlineState(deviceId), + DeviceOnlineStates.Timeout, + DeviceOnlineStates.Offline, + API_HEARTBEAT_STATE_TIMEOUT_SECONDS, // put the device into a timeout state if it misses it's scheduled heartbeat window... then mark as offline + ); + break; + case DeviceOnlineStates.Offline: + await this.updateDeviceModel( + deviceId, + DeviceOnlineStates.Offline, + ); + break; + default: + throw new Error( + `An unexpected value was encountered for the target device state: ${nextState}`, + ); + } } await this.rsmq.deleteMessageAsync({ From 8dd43e84b6f35add4130a3c305a875b406e3984d Mon Sep 17 00:00:00 2001 From: dcaputo-harmoni <65166251+dcaputo-harmoni@users.noreply.github.com> Date: Sun, 14 May 2023 08:47:34 -0400 Subject: [PATCH 2/2] Skip device heartbeat RSMQ records missing a deviceId property Change-type: patch --- src/features/device-heartbeat/index.ts | 50 +++++++++++++------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/features/device-heartbeat/index.ts b/src/features/device-heartbeat/index.ts index c7658f86c..a7220fc5b 100644 --- a/src/features/device-heartbeat/index.ts +++ b/src/features/device-heartbeat/index.ts @@ -298,30 +298,32 @@ export class DeviceOnlineStateManager extends EventEmitter<{ }; // raise and event for the state change... - switch (nextState) { - case DeviceOnlineStates.Timeout: - await this.updateDeviceModel( - deviceId, - DeviceOnlineStates.Timeout, - ); - this.scheduleChangeOfStateForDevice( - deviceId, - await this.getDeviceOnlineState(deviceId), - DeviceOnlineStates.Timeout, - DeviceOnlineStates.Offline, - API_HEARTBEAT_STATE_TIMEOUT_SECONDS, // put the device into a timeout state if it misses it's scheduled heartbeat window... then mark as offline - ); - break; - case DeviceOnlineStates.Offline: - await this.updateDeviceModel( - deviceId, - DeviceOnlineStates.Offline, - ); - break; - default: - throw new Error( - `An unexpected value was encountered for the target device state: ${nextState}`, - ); + if (deviceId) { + switch (nextState) { + case DeviceOnlineStates.Timeout: + await this.updateDeviceModel( + deviceId, + DeviceOnlineStates.Timeout, + ); + this.scheduleChangeOfStateForDevice( + deviceId, + await this.getDeviceOnlineState(deviceId), + DeviceOnlineStates.Timeout, + DeviceOnlineStates.Offline, + API_HEARTBEAT_STATE_TIMEOUT_SECONDS, // put the device into a timeout state if it misses it's scheduled heartbeat window... then mark as offline + ); + break; + case DeviceOnlineStates.Offline: + await this.updateDeviceModel( + deviceId, + DeviceOnlineStates.Offline, + ); + break; + default: + throw new Error( + `An unexpected value was encountered for the target device state: ${nextState}`, + ); + } } await this.rsmq.deleteMessageAsync({