From 0e3c0263922043b9d53a7eb3545622106f10100c Mon Sep 17 00:00:00 2001 From: Cameron Diver Date: Mon, 12 Oct 2020 11:34:27 +0100 Subject: [PATCH] Attempt a state report once every maxReportFrequency With the addition of the system information feature (CPU temp) etc if there wasn't any changes in the docker or config state of the device, updates in system information would not be sent to the API. Now we attempt to send data once every maxReportFrequency (although this does not mean that we will be sending data that often, we still only send the delta, if one exists) Change-type: patch Closes: #1481 Signed-off-by: Cameron Diver --- src/device-state/current-state.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/device-state/current-state.ts b/src/device-state/current-state.ts index a4a982ee..b6347559 100644 --- a/src/device-state/current-state.ts +++ b/src/device-state/current-state.ts @@ -243,12 +243,16 @@ const reportCurrentState = (): null => { }; export const startReporting = () => { - deviceState.on('change', () => { + const doReport = () => { if (!reportPending) { - // A latency of 100ms should be acceptable and - // allows avoiding catching docker at weird states reportCurrentState(); } - }); + }; + + // If the state changes, report it + deviceState.on('change', doReport); + // But check once every max report frequency to ensure that changes in system + // info are picked up (CPU temp etc) + setInterval(doReport, constants.maxReportFrequency); return reportCurrentState(); };