From cbe0c2983a46289da8262edc0bc81c51859d4176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hl=C3=B6=C3=B0ver=20Sigur=C3=B0sson?= Date: Thu, 21 Oct 2021 19:26:17 +0200 Subject: [PATCH] defer git-rev-sync call --- src/route/status.ts | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/route/status.ts b/src/route/status.ts index 6b341e8..182494d 100644 --- a/src/route/status.ts +++ b/src/route/status.ts @@ -10,10 +10,6 @@ import gitRev from "git-rev-sync"; let gitRevision = "unknown"; -try { - gitRevision = gitRev.long([process.cwd()]); -} catch {} - let ready = false; let lastKnownSessionUuid: CassandraTypes.TimeUuid; @@ -31,6 +27,10 @@ interface StatusSchema { function signalReady(): void { setTimeout(() => { if (!ready) { + try { + gitRevision = gitRev.long([process.cwd()]); + } catch {} + ready = true; } }, 2000); @@ -86,21 +86,22 @@ export async function statusRoute( next: (error?: string) => void ): Promise { if (!ready) { - return next("booting - not ready"); - } - try { - const currentStatus = await statusMapper.get({ - session: lastKnownSessionUuid, - }); - const delta = - Number.parseInt(currentStatus.arweave_height) - - Number.parseInt(currentStatus.gateway_height); - response.status(200).send({ - delta, - ...currentStatus, - vartex_git_revision: gitRevision, - }); - } catch (error) { - response.status(503).send(error); + response.sendStatus(503); + } else { + try { + const currentStatus = await statusMapper.get({ + session: lastKnownSessionUuid, + }); + const delta = + Number.parseInt(currentStatus.arweave_height) - + Number.parseInt(currentStatus.gateway_height); + response.status(200).send({ + delta, + ...currentStatus, + vartex_git_revision: gitRevision, + }); + } catch (error) { + response.sendStatus(503); + } } }