improved initialization
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Samuel Philipp 2021-01-10 20:49:09 +01:00
parent 12318e6c2e
commit a2b44e1731

View file

@ -60,18 +60,16 @@ const serviceStatePaths: { [service: string]: string } = config.groups
}, {});
let cache: CurrentStatus;
let uptimeStates = existsSync(join(process.cwd(), 'uptime.json')) ? JSON.parse(readFileSync(join(process.cwd(), 'uptime.json'), {encoding: 'utf-8'})) : null as { [id: string]: UptimeStatus; };
let uptimeStates = existsSync(join(process.cwd(), 'uptime.json')) ? JSON.parse(readFileSync(join(process.cwd(), 'uptime.json'), {encoding: 'utf-8'})) : {} as { [id: string]: UptimeStatus; };
// init serviceStates and uptimeStates
config.groups
.map(g => g.services).reduce((x, y) => x.concat(y), [])
.map(s => s.id).filter(id => !serviceStates[id])
.forEach(id => serviceStates[id] = 'operational');
if (!uptimeStates) {
uptimeStates = {};
for (let id in serviceStates) {
for (let id in serviceStates) {
if (serviceStates.hasOwnProperty(id)) {
updateServiceState(id, serviceStates[id]);
}
}
}
updateCache();