mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-22 11:37:00 +00:00
Split healthCheck out into separate module
GitOrigin-RevId: 96061812977d5c854e494cd44163b16a96722b17
This commit is contained in:
parent
c373db4f86
commit
a7be1f3430
3 changed files with 25 additions and 21 deletions
services/history-v1
|
@ -7,9 +7,9 @@ import { promisify } from 'node:util'
|
|||
import express from 'express'
|
||||
import logger from '@overleaf/logger'
|
||||
import Metrics from '@overleaf/metrics'
|
||||
import { healthCheck } from './backupVerifier/healthCheck.mjs'
|
||||
import {
|
||||
BackupCorruptedError,
|
||||
healthCheck,
|
||||
verifyBlob,
|
||||
} from './storage/lib/backupVerifier.mjs'
|
||||
import { mongodb } from './storage/index.js'
|
||||
|
|
24
services/history-v1/backupVerifier/healthCheck.mjs
Normal file
24
services/history-v1/backupVerifier/healthCheck.mjs
Normal file
|
@ -0,0 +1,24 @@
|
|||
import config from 'config'
|
||||
import { verifyProjectWithErrorContext } from '../storage/lib/backupVerifier.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)
|
||||
}
|
||||
}
|
|
@ -220,26 +220,6 @@ export async function verifyProject(historyId, endTimestamp) {
|
|||
|
||||
export class BackupCorruptedError extends OError {}
|
||||
export class BackupRPOViolationError extends OError {}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
export class BackupCorruptedMissingBlobError extends BackupCorruptedError {}
|
||||
export class BackupCorruptedInvalidBlobError extends BackupCorruptedError {}
|
||||
export class BackupRPOViolationChunkNotBackedUpError extends OError {}
|
||||
|
|
Loading…
Add table
Reference in a new issue