mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-24 07:46:41 +00:00
Catch errors in the target state poll so polling will always continue
Change-type: patch
This commit is contained in:
parent
62a36cbcdc
commit
dc187f0036
@ -612,31 +612,35 @@ export class APIBinder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async pollTargetState(skipFirstGet: boolean = false): Promise<void> {
|
private async pollTargetState(skipFirstGet: boolean = false): Promise<void> {
|
||||||
const appUpdatePollInterval = await this.config.get(
|
let appUpdatePollInterval;
|
||||||
'appUpdatePollInterval',
|
try {
|
||||||
);
|
appUpdatePollInterval = await this.config.get('appUpdatePollInterval');
|
||||||
|
if (!skipFirstGet) {
|
||||||
|
await this.getAndSetTargetState(false);
|
||||||
|
this.targetStateFetchErrors = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// We add a random jitter up to `maxApiJitterDelay` to
|
// We add a random jitter up to `maxApiJitterDelay` to
|
||||||
// space out poll requests
|
// space out poll requests
|
||||||
let pollInterval =
|
const pollInterval =
|
||||||
Math.random() * constants.maxApiJitterDelay + appUpdatePollInterval;
|
Math.random() * constants.maxApiJitterDelay + appUpdatePollInterval;
|
||||||
|
|
||||||
if (!skipFirstGet) {
|
await Bluebird.delay(pollInterval);
|
||||||
try {
|
|
||||||
await this.getAndSetTargetState(false);
|
|
||||||
this.targetStateFetchErrors = 0;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
pollInterval = Math.min(
|
const pollInterval = Math.min(
|
||||||
appUpdatePollInterval,
|
// If we failed fetching the appUpdatePollInterval then there won't have been any network
|
||||||
|
// requests so we default it to a low value of 10s since we don't need to worry about too
|
||||||
|
// many network requests
|
||||||
|
appUpdatePollInterval ?? 10000,
|
||||||
15000 * 2 ** this.targetStateFetchErrors,
|
15000 * 2 ** this.targetStateFetchErrors,
|
||||||
);
|
);
|
||||||
++this.targetStateFetchErrors;
|
++this.targetStateFetchErrors;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await Bluebird.delay(pollInterval);
|
await Bluebird.delay(pollInterval);
|
||||||
|
} finally {
|
||||||
await this.pollTargetState();
|
await this.pollTargetState();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async pinDevice({ app, commit }: DevicePinInfo) {
|
private async pinDevice({ app, commit }: DevicePinInfo) {
|
||||||
if (this.balenaApi == null) {
|
if (this.balenaApi == null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user