healthCheck.mjs 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import config from 'config'
  2. import { verifyProjectWithErrorContext } from '../storage/lib/backupVerifier.mjs'
  3. import {
  4. measureNeverBackedUpProjects,
  5. measurePendingChangesBeforeTime,
  6. } from './ProjectMetrics.mjs'
  7. import { getEndDateForRPO, RPO } from './utils.mjs'
  8. /** @type {Array<string>} */
  9. const HEALTH_CHECK_PROJECTS = JSON.parse(config.get('healthCheckProjects'))
  10. export async function healthCheck() {
  11. if (!Array.isArray(HEALTH_CHECK_PROJECTS)) {
  12. throw new Error('expected healthCheckProjects to be an array')
  13. }
  14. if (HEALTH_CHECK_PROJECTS.length !== 2) {
  15. throw new Error('expected 2 healthCheckProjects')
  16. }
  17. if (!HEALTH_CHECK_PROJECTS.some(id => id.length === 24)) {
  18. throw new Error('expected mongo id in healthCheckProjects')
  19. }
  20. if (!HEALTH_CHECK_PROJECTS.some(id => id.length < 24)) {
  21. throw new Error('expected postgres id in healthCheckProjects')
  22. }
  23. for (const historyId of HEALTH_CHECK_PROJECTS) {
  24. await verifyProjectWithErrorContext(historyId)
  25. }
  26. await measurePendingChangesBeforeTime(getEndDateForRPO(2))
  27. await measureNeverBackedUpProjects(getEndDateForRPO(2))
  28. }