diff --git a/src/config/configLoader.ts b/src/config/configLoader.ts index 63ff948..21a37c5 100644 --- a/src/config/configLoader.ts +++ b/src/config/configLoader.ts @@ -37,6 +37,9 @@ function loadConfig(): Config { port: process.env.HEALTH_PORT ? parseInt(process.env.HEALTH_PORT, 10) : undefined, + maxStaleMs: process.env.HEALTH_MAX_STALE_MS + ? parseInt(process.env.HEALTH_MAX_STALE_MS, 10) + : undefined, }, }; diff --git a/src/config/configSchema.ts b/src/config/configSchema.ts index 57e0d32..e0d639a 100644 --- a/src/config/configSchema.ts +++ b/src/config/configSchema.ts @@ -35,6 +35,11 @@ export const healthConfigSchema = z.object({ enabled: z.boolean().default(true), host: z.string().default('::'), port: z.number().int().positive().default(3000), + maxStaleMs: z + .number() + .int() + .positive() + .default(10 * 60 * 1000), // 10 minutes }); export const configSchema = z.object({ diff --git a/src/health.ts b/src/health.ts index 508c87e..e6ac299 100644 --- a/src/health.ts +++ b/src/health.ts @@ -37,7 +37,10 @@ export function createHealthRequestHandler({ } const postgresStatus = await performPostgresCheck(pool, logger); - const synchronizerStatus = evaluateSynchronizer(synchronizer); + const synchronizerStatus = evaluateSynchronizer( + synchronizer, + config.health.maxStaleMs, + ); const isHealthy = postgresStatus.status === 'ok' && synchronizerStatus.status === 'ok'; @@ -88,6 +91,7 @@ export async function performPostgresCheck( export function evaluateSynchronizer( synchronizer: Synchronizer, + maxStaleMs: number, ): HealthComponentStatus { const metrics = synchronizer.getMetrics(); if (!metrics.lastSyncTime) { @@ -110,7 +114,6 @@ export function evaluateSynchronizer( } const now = Date.now(); - const maxStaleMs = 10 * 60 * 1000; // 10 minutes const timeSinceLastSync = now - lastSyncTimestamp; if (timeSinceLastSync > maxStaleMs) { diff --git a/src/synchronizer/meilisearch/createMeiliSearchSynchronizer.ts b/src/synchronizer/meilisearch/createMeiliSearchSynchronizer.ts index 83b2a9c..151c9d0 100644 --- a/src/synchronizer/meilisearch/createMeiliSearchSynchronizer.ts +++ b/src/synchronizer/meilisearch/createMeiliSearchSynchronizer.ts @@ -88,23 +88,6 @@ export function createMeiliSearchSynchronizer( stack: error instanceof Error ? error.stack : undefined, }, }); - // Stop change detection and reset state on sync failure. - isRunning = false; - await changeDetection.stop().catch(stopError => { - logger.warn( - 'Error while stopping change detection after sync failure:', - { - metadata: { - error: - stopError instanceof Error - ? stopError.message - : String(stopError), - }, - }, - ); - }); - - throw error; } };