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