From ca1d8b84f4124fc5933fba894fc8e249dc90e944 Mon Sep 17 00:00:00 2001 From: Abdulrhmn Ghanem Date: Fri, 7 Jul 2023 15:31:30 +0300 Subject: [PATCH] Add healthchek for `partinfo.kitspace.org` --- processor/src/app.ts | 3 +++ processor/src/healthChecks.ts | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 processor/src/healthChecks.ts diff --git a/processor/src/app.ts b/processor/src/app.ts index 6e13a1d8c9..4da670c7ac 100644 --- a/processor/src/app.ts +++ b/processor/src/app.ts @@ -1,4 +1,5 @@ import { watch } from './watcher.js' +import { checkPartInfoHealth } from './healthChecks.js' import { createWorkers } from './workers.js' export interface KitspaceProcessorApp { @@ -14,6 +15,8 @@ export async function createApp(repoDir: string): Promise }, } + await checkPartInfoHealth() + const unwatch = await watch(repoDir) app.cleanup.push(unwatch) diff --git a/processor/src/healthChecks.ts b/processor/src/healthChecks.ts new file mode 100644 index 0000000000..770c79843b --- /dev/null +++ b/processor/src/healthChecks.ts @@ -0,0 +1,20 @@ +import fetch from 'node-fetch' + +import { log } from './log.js' + +/** + * Check the health of the partinfo.kitspace.org by checking the graphql IDE + */ +export async function checkPartInfoHealth() { + const endpoint = 'https://partinfo.kitspace.org/graphql' + const res = await fetch(endpoint, { + headers: { + accept: 'text/html', + }, + }) + if (res.status !== 200) { + throw new Error(`${endpoint} health check failed with status ${res.status}`) + } else { + log.debug(`${endpoint} health check passed`) + } +}