overleaf-cep/services/history-v1/backupVerifier/healthCheck.mjs
Andrew Rumble 99ab41fd76 Allow scaling in getEndDateForRPO
RPO can now be scaled to allow a little extra grace in certain
circumstances.

Co-authored-by: Brian Gough <brian.gough@overleaf.com>
GitOrigin-RevId: fa60a9ffe966977e396b5645919ddd1451fb1b7a
2025-03-27 14:16:40 +00:00

32 lines
1.1 KiB
JavaScript

import config from 'config'
import { verifyProjectWithErrorContext } from '../storage/lib/backupVerifier.mjs'
import {
measureNeverBackedUpProjects,
measurePendingChangesBeforeTime,
} from './ProjectMetrics.mjs'
import { getEndDateForRPO, RPO } from './utils.mjs'
/** @type {Array<string>} */
const HEALTH_CHECK_PROJECTS = JSON.parse(config.get('healthCheckProjects'))
export async function healthCheck() {
if (!Array.isArray(HEALTH_CHECK_PROJECTS)) {
throw new Error('expected healthCheckProjects to be an array')
}
if (HEALTH_CHECK_PROJECTS.length !== 2) {
throw new Error('expected 2 healthCheckProjects')
}
if (!HEALTH_CHECK_PROJECTS.some(id => id.length === 24)) {
throw new Error('expected mongo id in healthCheckProjects')
}
if (!HEALTH_CHECK_PROJECTS.some(id => id.length < 24)) {
throw new Error('expected postgres id in healthCheckProjects')
}
for (const historyId of HEALTH_CHECK_PROJECTS) {
await verifyProjectWithErrorContext(historyId)
}
await measurePendingChangesBeforeTime(getEndDateForRPO(2))
await measureNeverBackedUpProjects(getEndDateForRPO(2))
}