mirror of
https://github.com/eliasstepanik/core.git
synced 2026-01-22 22:18:29 +00:00
fix: add check to wait for neo4j
This commit is contained in:
parent
6c37b41ca4
commit
c5407be54d
@ -1,6 +1,6 @@
|
|||||||
import { logger } from "~/services/logger.service";
|
import { logger } from "~/services/logger.service";
|
||||||
import { fetchAndSaveStdioIntegrations } from "~/trigger/utils/mcp";
|
import { fetchAndSaveStdioIntegrations } from "~/trigger/utils/mcp";
|
||||||
import { initNeo4jSchemaOnce } from "~/lib/neo4j.server";
|
import { initNeo4jSchemaOnce, verifyConnectivity } from "~/lib/neo4j.server";
|
||||||
import { env } from "~/env.server";
|
import { env } from "~/env.server";
|
||||||
import { initWorkers, shutdownWorkers } from "~/bullmq/start-workers";
|
import { initWorkers, shutdownWorkers } from "~/bullmq/start-workers";
|
||||||
import { trackConfig } from "~/services/telemetry.server";
|
import { trackConfig } from "~/services/telemetry.server";
|
||||||
@ -8,6 +8,31 @@ import { trackConfig } from "~/services/telemetry.server";
|
|||||||
// Global flag to ensure startup only runs once per server process
|
// Global flag to ensure startup only runs once per server process
|
||||||
let startupInitialized = false;
|
let startupInitialized = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wait for Neo4j to be ready before initializing schema
|
||||||
|
*/
|
||||||
|
async function waitForNeo4j(maxRetries = 30, retryDelay = 2000) {
|
||||||
|
logger.info("Waiting for Neo4j to be ready...");
|
||||||
|
|
||||||
|
for (let i = 0; i < maxRetries; i++) {
|
||||||
|
try {
|
||||||
|
const connected = await verifyConnectivity();
|
||||||
|
if (connected) {
|
||||||
|
logger.info("✓ Neo4j is ready!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// Connection failed, will retry
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info(`Neo4j not ready, retrying... (${i + 1}/${maxRetries})`);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.error("Failed to connect to Neo4j after maximum retries");
|
||||||
|
throw new Error("Failed to connect to Neo4j after maximum retries");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize all startup services once per server process
|
* Initialize all startup services once per server process
|
||||||
* Safe to call multiple times - will only run initialization once
|
* Safe to call multiple times - will only run initialization once
|
||||||
@ -80,6 +105,9 @@ export async function initializeStartupServices() {
|
|||||||
try {
|
try {
|
||||||
logger.info("Starting application initialization...");
|
logger.info("Starting application initialization...");
|
||||||
|
|
||||||
|
// Wait for Neo4j to be ready
|
||||||
|
await waitForNeo4j();
|
||||||
|
|
||||||
// Initialize Neo4j schema
|
// Initialize Neo4j schema
|
||||||
await initNeo4jSchemaOnce();
|
await initNeo4jSchemaOnce();
|
||||||
logger.info("Neo4j schema initialization completed");
|
logger.info("Neo4j schema initialization completed");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user