improved initialization #61

Manually merged
samuel-p merged 1 commit from develop into master 2021-01-10 20:00:05 +00:00

View file

@ -60,17 +60,15 @@ const serviceStatePaths: { [service: string]: string } = config.groups
}, {}); }, {});
let cache: CurrentStatus; 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 config.groups
.map(g => g.services).reduce((x, y) => x.concat(y), []) .map(g => g.services).reduce((x, y) => x.concat(y), [])
.map(s => s.id).filter(id => !serviceStates[id]) .map(s => s.id).filter(id => !serviceStates[id])
.forEach(id => serviceStates[id] = 'operational'); .forEach(id => serviceStates[id] = 'operational');
if (!uptimeStates) { for (let id in serviceStates) {
uptimeStates = {}; if (serviceStates.hasOwnProperty(id)) {
for (let id in serviceStates) { updateServiceState(id, serviceStates[id]);
if (serviceStates.hasOwnProperty(id)) {
updateServiceState(id, serviceStates[id]);
}
} }
} }
updateCache(); updateCache();