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
This commit is contained in:
Felipe Lalanne 2022-09-30 19:38:10 +00:00
parent ef0dcc39dc
commit b4514631b1

View File

@ -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();
}