Merge pull request #1331 from balena-io/always-poll

Catch errors in the target state poll so polling will always continue
This commit is contained in:
Page- 2020-05-18 15:02:21 +01:00 committed by GitHub
commit 02be46068b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -612,30 +612,34 @@ export class APIBinder {
}
private async pollTargetState(skipFirstGet: boolean = false): Promise<void> {
const appUpdatePollInterval = await this.config.get(
'appUpdatePollInterval',
);
// We add a random jitter up to `maxApiJitterDelay` to
// space out poll requests
let pollInterval =
Math.random() * constants.maxApiJitterDelay + appUpdatePollInterval;
if (!skipFirstGet) {
try {
let appUpdatePollInterval;
try {
appUpdatePollInterval = await this.config.get('appUpdatePollInterval');
if (!skipFirstGet) {
await this.getAndSetTargetState(false);
this.targetStateFetchErrors = 0;
} catch (e) {
pollInterval = Math.min(
appUpdatePollInterval,
15000 * 2 ** this.targetStateFetchErrors,
);
++this.targetStateFetchErrors;
}
}
await Bluebird.delay(pollInterval);
await this.pollTargetState();
// We add a random jitter up to `maxApiJitterDelay` to
// space out poll requests
const pollInterval =
Math.random() * constants.maxApiJitterDelay + appUpdatePollInterval;
await Bluebird.delay(pollInterval);
} catch (e) {
const pollInterval = Math.min(
// 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,
);
++this.targetStateFetchErrors;
await Bluebird.delay(pollInterval);
} finally {
await this.pollTargetState();
}
}
private async pinDevice({ app, commit }: DevicePinInfo) {