Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/config/configLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};

Expand Down
5 changes: 5 additions & 0 deletions src/config/configSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
7 changes: 5 additions & 2 deletions src/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -88,6 +91,7 @@ export async function performPostgresCheck(

export function evaluateSynchronizer(
synchronizer: Synchronizer,
maxStaleMs: number,
): HealthComponentStatus {
const metrics = synchronizer.getMetrics();
if (!metrics.lastSyncTime) {
Expand All @@ -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) {
Expand Down
17 changes: 0 additions & 17 deletions src/synchronizer/meilisearch/createMeiliSearchSynchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

Expand Down