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 <cameron@balena.io>
This commit is contained in:
Cameron Diver 2020-10-12 11:34:27 +01:00
parent 975129188a
commit 0e3c026392

View File

@ -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();
};