Throttle state report patches to once per 10 seconds

Change-type: patch
Closes: #1158
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2019-12-19 12:29:20 +00:00
parent 231284e06b
commit 4b0f431f9b
No known key found for this signature in database
GPG Key ID: 49690ED87032539F
2 changed files with 5 additions and 3 deletions

View File

@ -13,6 +13,7 @@ import Database from './db';
import { EventTracker } from './event-tracker'; import { EventTracker } from './event-tracker';
import { loadBackupFromMigration } from './lib/migration'; import { loadBackupFromMigration } from './lib/migration';
import constants = require('./lib/constants');
import { import {
ContractValidationError, ContractValidationError,
ContractViolationError, ContractViolationError,
@ -485,7 +486,7 @@ export class APIBinder {
}; };
} }
private async report() { private report = _.throttle(async () => {
const conf = await this.config.getMany([ const conf = await this.config.getMany([
'deviceId', 'deviceId',
'apiTimeout', 'apiTimeout',
@ -531,7 +532,7 @@ export class APIBinder {
throw e; throw e;
} }
} }
} }, constants.maxReportFrequency);
private reportCurrentState(): null { private reportCurrentState(): null {
(async () => { (async () => {
@ -600,7 +601,6 @@ export class APIBinder {
} }
private async pollTargetState(isInitialCall: boolean = false): Promise<void> { private async pollTargetState(isInitialCall: boolean = false): Promise<void> {
// TODO: Remove the checkInt here with the config changes
const { const {
appUpdatePollInterval, appUpdatePollInterval,
instantUpdates, instantUpdates,

View File

@ -56,6 +56,8 @@ const constants = {
backoffIncrement: 500, backoffIncrement: 500,
supervisorNetworkSubnet: '10.114.104.0/25', supervisorNetworkSubnet: '10.114.104.0/25',
supervisorNetworkGateway: '10.114.104.1', supervisorNetworkGateway: '10.114.104.1',
// How often can we report our state to the server in ms
maxReportFrequency: 10 * 1000,
}; };
if (process.env.DOCKER_HOST == null) { if (process.env.DOCKER_HOST == null) {