Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
defer git-rev-sync call
Browse files Browse the repository at this point in the history
  • Loading branch information
hlolli committed Oct 21, 2021
1 parent e65b274 commit cbe0c29
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/route/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +27,10 @@ interface StatusSchema {
function signalReady(): void {
setTimeout(() => {
if (!ready) {
try {
gitRevision = gitRev.long([process.cwd()]);
} catch {}

ready = true;
}
}, 2000);
Expand Down Expand Up @@ -86,21 +86,22 @@ export async function statusRoute(
next: (error?: string) => void
): Promise<void> {
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);
}
}
}

0 comments on commit cbe0c29

Please sign in to comment.