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

Commit

Permalink
delay readiness on status route during boot
Browse files Browse the repository at this point in the history
  • Loading branch information
hlolli committed Oct 21, 2021
1 parent 30892ae commit e65b274
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
37 changes: 18 additions & 19 deletions src/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,25 @@ export function start(): void {
});
});

new Promise<void>((resolve) => setTimeout(resolve, 1000)).then(() => {
initializeStatusSession(cassandraClient, session.uuid).then(
(sessionUuid: CassandraTypes.TimeUuid) => {
session.uuid = sessionUuid;

startSync({ session, isTesting: process.env.NODE_ENV === "test" });

if (isGatewayNodeModeEnabled) {
// recheck every minute if session changes
setInterval(() => {
initializeStatusSession(cassandraClient, session.uuid).then(
(newSessionUuid: CassandraTypes.TimeUuid) => {
session.uuid = newSessionUuid;
}
);
}, 60 * 1000);
}
initializeStatusSession(cassandraClient, session.uuid).then(
(sessionUuid: CassandraTypes.TimeUuid) => {
session.uuid = sessionUuid;
// just flush
console.log("...");
startSync({ session, isTesting: process.env.NODE_ENV === "test" });

if (isGatewayNodeModeEnabled) {
// recheck every minute if session changes
setInterval(() => {
initializeStatusSession(cassandraClient, session.uuid).then(
(newSessionUuid: CassandraTypes.TimeUuid) => {
session.uuid = newSessionUuid;
}
);
}, 60 * 1000);
}
);
});
}
);
});
app.get(
"/graphql",
Expand Down
17 changes: 15 additions & 2 deletions src/route/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ try {
gitRevision = gitRev.long([process.cwd()]);
} catch {}

let ready = false;

let lastKnownSessionUuid: CassandraTypes.TimeUuid;

interface StatusSchema {
Expand All @@ -26,6 +28,14 @@ interface StatusSchema {
current_migrations: Record<string, string>;
}

function signalReady(): void {
setTimeout(() => {
if (!ready) {
ready = true;
}
}, 2000);
}

export const initializeStatusSession = async (
cassandraClient: CassandraClient,
sessionUuid: CassandraTypes.TimeUuid
Expand All @@ -35,10 +45,12 @@ export const initializeStatusSession = async (
);

if (isGatewayNodeModeEnabled && !R.isEmpty(maybeLastSession.rows)) {
signalReady();
lastKnownSessionUuid = maybeLastSession.rows[0].session;
return maybeLastSession.rows[0].session;
} else if (isGatewayNodeModeEnabled) {
lastKnownSessionUuid = sessionUuid;
signalReady();
return sessionUuid;
}

Expand All @@ -63,6 +75,7 @@ export const initializeStatusSession = async (
await statusMapper.insert(
R.mergeAll([lastSession, { session: sessionUuid, status: "BOOTING" }])
);
signalReady();
lastKnownSessionUuid = sessionUuid;
return sessionUuid;
};
Expand All @@ -72,8 +85,8 @@ export async function statusRoute(
response: Response,
next: (error?: string) => void
): Promise<void> {
if (!lastKnownSessionUuid) {
return next("not ready");
if (!ready) {
return next("booting - not ready");
}
try {
const currentStatus = await statusMapper.get({
Expand Down

0 comments on commit e65b274

Please sign in to comment.