mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-03 21:26:04 +00:00
misc: improved commnts
This commit is contained in:
@@ -87,7 +87,8 @@ export const runMigrations = async ({ applicationDb, auditLogDb, logger, onMigra
|
|||||||
await applicationDb.transaction(async (tx) => {
|
await applicationDb.transaction(async (tx) => {
|
||||||
await tx.raw("SELECT pg_advisory_xact_lock(?)", [PgSqlLock.BootUpMigration]);
|
await tx.raw("SELECT pg_advisory_xact_lock(?)", [PgSqlLock.BootUpMigration]);
|
||||||
|
|
||||||
// Signal that this container is running migrations
|
// Signal that this container is running migrations so that it can be marked as healthy/alive
|
||||||
|
// This is to prevent the container from being killed by the orchestrator
|
||||||
if (onMigrationLockAcquired) {
|
if (onMigrationLockAcquired) {
|
||||||
onMigrationLockAcquired();
|
onMigrationLockAcquired();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,6 @@ const run = async () => {
|
|||||||
envConfig
|
envConfig
|
||||||
});
|
});
|
||||||
|
|
||||||
// Setup signal handlers
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
process.on("SIGINT", async () => {
|
process.on("SIGINT", async () => {
|
||||||
await server.close();
|
await server.close();
|
||||||
@@ -117,7 +116,6 @@ const run = async () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start listening BEFORE migrations
|
|
||||||
await server.listen({
|
await server.listen({
|
||||||
port: envConfig.PORT,
|
port: envConfig.PORT,
|
||||||
host: envConfig.HOST
|
host: envConfig.HOST
|
||||||
@@ -144,7 +142,6 @@ const run = async () => {
|
|||||||
|
|
||||||
logger.info("Migrations complete. Marking server as READY...");
|
logger.info("Migrations complete. Marking server as READY...");
|
||||||
|
|
||||||
// Now mark server as ready - it can accept traffic
|
|
||||||
markServerReady();
|
markServerReady();
|
||||||
|
|
||||||
logger.info("Server is ready to accept traffic");
|
logger.info("Server is ready to accept traffic");
|
||||||
|
|||||||
@@ -38,11 +38,9 @@ import { registerServeUI } from "./plugins/serve-ui";
|
|||||||
import { fastifySwagger } from "./plugins/swagger";
|
import { fastifySwagger } from "./plugins/swagger";
|
||||||
import { registerRoutes } from "./routes";
|
import { registerRoutes } from "./routes";
|
||||||
|
|
||||||
// Monitor event loop for readiness checks
|
|
||||||
const histogram = monitorEventLoopDelay({ resolution: 20 });
|
const histogram = monitorEventLoopDelay({ resolution: 20 });
|
||||||
histogram.enable();
|
histogram.enable();
|
||||||
|
|
||||||
// Server state tracking
|
|
||||||
const serverState = {
|
const serverState = {
|
||||||
isReady: false,
|
isReady: false,
|
||||||
isRunningMigrations: false,
|
isRunningMigrations: false,
|
||||||
@@ -171,7 +169,6 @@ export const main = async ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Global preHandler to block requests during migrations
|
// Global preHandler to block requests during migrations
|
||||||
// Excludes /api/health and /api/ready endpoints
|
|
||||||
server.addHook("preHandler", async (request, reply) => {
|
server.addHook("preHandler", async (request, reply) => {
|
||||||
if (request.url === "/api/health" || request.url === "/api/ready") {
|
if (request.url === "/api/health" || request.url === "/api/ready") {
|
||||||
return;
|
return;
|
||||||
@@ -188,7 +185,6 @@ export const main = async ({
|
|||||||
server.get("/api/ready", async (request, reply) => {
|
server.get("/api/ready", async (request, reply) => {
|
||||||
const cfg = getConfig();
|
const cfg = getConfig();
|
||||||
|
|
||||||
// Calculate event loop statistics
|
|
||||||
const meanLagMs = histogram.mean / 1e6;
|
const meanLagMs = histogram.mean / 1e6;
|
||||||
const maxLagMs = histogram.max / 1e6;
|
const maxLagMs = histogram.max / 1e6;
|
||||||
const p99LagMs = histogram.percentile(99) / 1e6;
|
const p99LagMs = histogram.percentile(99) / 1e6;
|
||||||
@@ -252,7 +248,6 @@ export const main = async ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Functions to manage server state
|
|
||||||
export const markServerReady = () => {
|
export const markServerReady = () => {
|
||||||
serverState.isReady = true;
|
serverState.isReady = true;
|
||||||
serverState.isRunningMigrations = false;
|
serverState.isRunningMigrations = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user