From b4514631b11c24c58342021e1a5b62add5a8c476 Mon Sep 17 00:00:00 2001 From: Felipe Lalanne Date: Fri, 30 Sep 2022 19:38:10 +0000 Subject: [PATCH] Start state engine and API binder in parallel The state engine and preloading is performed before the device gets a chance to register, while this is desirable for preloaded apps, it introduces a delay on registration which is known to cause issues since the VPN is also trying to connect at the same time. This triggers a simultaneous start of the device engine, the API binder and the supevisor API to avoid delays. Change-type: patch --- src/supervisor.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/supervisor.ts b/src/supervisor.ts index 2ab3384d..b98020ef 100644 --- a/src/supervisor.ts +++ b/src/supervisor.ts @@ -59,17 +59,21 @@ export class Supervisor { await normaliseLegacyDatabase(); } - await deviceState.loadInitialState(); - - log.info('Starting API server'); - this.api = new SupervisorAPI({ - routers: [apiBinder.router, deviceState.router], - healthchecks: [apiBinder.healthcheck, deviceState.healthcheck], - }); - this.api.listen(conf.listenPort, conf.apiTimeout); - deviceState.on('shutdown', () => this.api.stop()); - - await apiBinder.start(); + // Start the state engine, the device API and API binder + // in parallel + await Promise.all([ + deviceState.loadInitialState(), + (() => { + log.info('Starting API server'); + this.api = new SupervisorAPI({ + routers: [apiBinder.router, deviceState.router], + healthchecks: [apiBinder.healthcheck, deviceState.healthcheck], + }); + this.api.listen(conf.listenPort, conf.apiTimeout); + deviceState.on('shutdown', () => this.api.stop()); + })(), + apiBinder.start(), + ]); logMonitor.start(); }