Просмотр исходного кода

Split healthCheck out into separate module

GitOrigin-RevId: 847d00b696fe6d82f4bd5fea8f9130437c68e7b2
Andrew Rumble 1 год назад
Родитель
Сommit
273ae4aecd

+ 1 - 1
services/history-v1/backup-verifier-app.mjs

@@ -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 - 0
services/history-v1/backupVerifier/healthCheck.mjs

@@ -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)
+  }
+}

+ 0 - 20
services/history-v1/storage/lib/backupVerifier.mjs

@@ -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 {}