From a2b44e1731c4a3e028dd533799c5d57849e28deb Mon Sep 17 00:00:00 2001 From: samuel-p Date: Sun, 10 Jan 2021 20:49:09 +0100 Subject: [PATCH] improved initialization --- src/main.status.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main.status.ts b/src/main.status.ts index 879afed..a973479 100644 --- a/src/main.status.ts +++ b/src/main.status.ts @@ -60,17 +60,15 @@ 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) { - if (serviceStates.hasOwnProperty(id)) { - updateServiceState(id, serviceStates[id]); - } +for (let id in serviceStates) { + if (serviceStates.hasOwnProperty(id)) { + updateServiceState(id, serviceStates[id]); } } updateCache();