mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-19 13:47:54 +00:00
Use delay instead of interval to recursively report state
Change-type: patch Signed-off-by: 20k-ultra <3946250+20k-ultra@users.noreply.github.com>
This commit is contained in:
parent
4557644149
commit
2e81a7328e
@ -1,5 +1,6 @@
|
||||
import * as url from 'url';
|
||||
import * as _ from 'lodash';
|
||||
import { delay } from 'bluebird';
|
||||
import { CoreOptions } from 'request';
|
||||
|
||||
import * as constants from '../lib/constants';
|
||||
@ -141,15 +142,24 @@ export async function startReporting() {
|
||||
);
|
||||
const doReport = async () => {
|
||||
if (!reportPending) {
|
||||
throttledReport(reportConfigs);
|
||||
await throttledReport(reportConfigs);
|
||||
}
|
||||
};
|
||||
|
||||
// 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);
|
||||
// Try to perform a report right away
|
||||
return doReport();
|
||||
|
||||
async function recursivelyReport(delayBy: number) {
|
||||
try {
|
||||
// Try to send current state
|
||||
await doReport();
|
||||
} finally {
|
||||
// Wait until we want to report again
|
||||
await delay(delayBy);
|
||||
// Try to report again
|
||||
await recursivelyReport(delayBy);
|
||||
}
|
||||
}
|
||||
|
||||
return recursivelyReport(constants.maxReportFrequency);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user