mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Split healthCheck out into separate module
GitOrigin-RevId: 847d00b696fe6d82f4bd5fea8f9130437c68e7b2
This commit is contained in:
@@ -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 {}
|
||||
|
||||
Reference in New Issue
Block a user