From a9c80cc6fd8d3e11d86172d49d88869e1d89ad27 Mon Sep 17 00:00:00 2001 From: onmax Date: Sat, 17 Aug 2024 07:12:58 +0200 Subject: [PATCH] testing prod --- server/api/vts/health.get.ts | 70 ++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/server/api/vts/health.get.ts b/server/api/vts/health.get.ts index e1a8b76..45a5ef4 100644 --- a/server/api/vts/health.get.ts +++ b/server/api/vts/health.get.ts @@ -1,7 +1,5 @@ import { max, count, } from 'drizzle-orm'; -import { NimiqRPCClient } from 'nimiq-rpc-client-ts'; import { Range, getRange } from 'nimiq-vts'; -import { getMissingEpochs } from '~~/server/database/utils'; export enum HealthFlag { MissingEpochs = 'missing-epochs', @@ -31,8 +29,8 @@ export default defineEventHandler(async (event) => { if (!url) throw new Error('Missing RPC URL in runtime config') console.log('RPC URL:', url) - const rpcClient = new NimiqRPCClient(new URL(url)) - console.log('RPC Client:', rpcClient) + // const rpcClient = new NimiqRPCClient(new URL(url)) + // console.log('RPC Client:', rpcClient) // Get the latest epoch number in the activity table const latestActivityBlock = await useDrizzle() @@ -42,10 +40,10 @@ export default defineEventHandler(async (event) => { .then((row) => row?.epoch ?? -1); console.log('Latest Activity Block:', latestActivityBlock) - const { data: latestFetchedEpoch, error: errorLatestFetchedEpoch } = await rpcClient.policy.getEpochAt(latestActivityBlock) - if (errorLatestFetchedEpoch) - throw errorLatestFetchedEpoch; - console.log('Latest Fetched Epoch:', latestFetchedEpoch) + // const { data: latestFetchedEpoch, error: errorLatestFetchedEpoch } = await rpcClient.policy.getEpochAt(latestActivityBlock) + // if (errorLatestFetchedEpoch) + // throw errorLatestFetchedEpoch; + // console.log('Latest Fetched Epoch:', latestFetchedEpoch) // Get the total number of validators const totalValidators = await useDrizzle() @@ -64,40 +62,40 @@ export default defineEventHandler(async (event) => { console.log('Fetched Epochs:', fetchedEpochs) - const { data: headBlockNumber, error: errorHeadBlockNumber } = await rpcClient.blockchain.getBlockNumber() - if (errorHeadBlockNumber) - throw errorHeadBlockNumber; - console.log('Head Block Number:', headBlockNumber) - const { data: currentEpoch, error: errorCurrentEpoch } = await rpcClient.blockchain.getEpochNumber() - if (errorCurrentEpoch) - throw errorCurrentEpoch; - console.log('Current Epoch:', currentEpoch) + // const { data: headBlockNumber, error: errorHeadBlockNumber } = await rpcClient.blockchain.getBlockNumber() + // if (errorHeadBlockNumber) + // throw errorHeadBlockNumber; + // console.log('Head Block Number:', headBlockNumber) + // const { data: currentEpoch, error: errorCurrentEpoch } = await rpcClient.blockchain.getEpochNumber() + // if (errorCurrentEpoch) + // throw errorCurrentEpoch; + // console.log('Current Epoch:', currentEpoch) - const range = await getRange(rpcClient); - console.log('Range:', range) - const missingEpochs = await getMissingEpochs(range); - console.log('Missing Epochs:', missingEpochs) + // const range = await getRange(rpcClient); + // console.log('Range:', range) + // const missingEpochs = await getMissingEpochs(range); + // console.log('Missing Epochs:', missingEpochs) - const isSynced = missingEpochs.length === 0; - console.log('Is Synced:', isSynced) + // const isSynced = missingEpochs.length === 0; + // console.log('Is Synced:', isSynced) const flags: HealthFlag[] = [] - if (!isSynced) flags.push(HealthFlag.MissingEpochs) + // if (!isSynced) flags.push(HealthFlag.MissingEpochs) // Combine all the data into a HealthStatus object - const healthStatus: HealthStatus = { - latestFetchedEpoch, - totalValidators, - headBlockNumber, - currentEpoch, - range, - missingEpochs, - isSynced, - flags, - fetchedEpochs, - }; - console.log('Health Status:', healthStatus) + // const healthStatus: HealthStatus = { + // latestFetchedEpoch, + // totalValidators, + // headBlockNumber, + // currentEpoch, + // range, + // missingEpochs, + // isSynced, + // flags, + // fetchedEpochs, + // }; + // console.log('Health Status:', healthStatus) // Return the health status setResponseStatus(event, 200); - return healthStatus; + return { status: 'ok' } as const; }); \ No newline at end of file