Merge pull request #2035 from balena-os/parallel-start

Start state engine and API binder in parallel
This commit is contained in:
bulldozer-balena[bot] 2022-10-10 19:40:51 +00:00 committed by GitHub
commit dfcaa2ecb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -59,17 +59,21 @@ export class Supervisor {
await normaliseLegacyDatabase(); await normaliseLegacyDatabase();
} }
await deviceState.loadInitialState(); // Start the state engine, the device API and API binder
// in parallel
log.info('Starting API server'); await Promise.all([
this.api = new SupervisorAPI({ deviceState.loadInitialState(),
routers: [apiBinder.router, deviceState.router], (() => {
healthchecks: [apiBinder.healthcheck, deviceState.healthcheck], log.info('Starting API server');
}); this.api = new SupervisorAPI({
this.api.listen(conf.listenPort, conf.apiTimeout); routers: [apiBinder.router, deviceState.router],
deviceState.on('shutdown', () => this.api.stop()); healthchecks: [apiBinder.healthcheck, deviceState.healthcheck],
});
await apiBinder.start(); this.api.listen(conf.listenPort, conf.apiTimeout);
deviceState.on('shutdown', () => this.api.stop());
})(),
apiBinder.start(),
]);
logMonitor.start(); logMonitor.start();
} }