diff --git a/api/src/features/health/health.controller.ts b/api/src/features/health/health.controller.ts index eecd58471..3df728bec 100644 --- a/api/src/features/health/health.controller.ts +++ b/api/src/features/health/health.controller.ts @@ -14,7 +14,7 @@ export class HealthController { private health: HealthCheckService, private dbHealth: DatabaseHealthIndicator, private redisHealth: RedisHealthIndicator, - private providerHealth: NetworksHealthIndicator, + private networksHealth: NetworksHealthIndicator, @InjectRedis() private readonly redis: Redis, @InjectRedisSubscriber() @@ -29,7 +29,7 @@ export class HealthController { () => this.dbHealth.check('Database'), () => this.redisHealth.check('Redis::default', this.redis), () => this.redisHealth.check('Redis::subscriber', this.redisSub), - () => this.providerHealth.check('Provider'), + () => this.networksHealth.check('Networks'), ]); } } diff --git a/api/src/features/util/networks/networks.health.ts b/api/src/features/util/networks/networks.health.ts index 96844762a..a71d9f7b6 100644 --- a/api/src/features/util/networks/networks.health.ts +++ b/api/src/features/util/networks/networks.health.ts @@ -1,7 +1,6 @@ import { Injectable } from '@nestjs/common'; import { HealthIndicator } from '@nestjs/terminus'; -import { Network, NetworksService } from './networks.service'; -import { fromPromise } from 'neverthrow'; +import { NetworksService } from './networks.service'; @Injectable() export class NetworksHealthIndicator extends HealthIndicator { @@ -10,31 +9,28 @@ export class NetworksHealthIndicator extends HealthIndicator { } async check(key: string) { - const networks: Network[] = []; // Array.fromAsync(...) when supported - for await (const network of this.networks) { - networks.push(network); - } - const statuses = Object.fromEntries( await Promise.all( - networks.map(async (c) => { - const r = await fromPromise( - (async () => ({ blockNumber: await c.getBlockNumber() }))(), - (e) => ({ error: e as Error }), - ); + [...this.networks.all()] + .filter((n) => n.chain.key !== 'zksync-local') + .map(async (c) => { + const status = await c.status(); - return [ - c.chain.key, - { - healthy: r.isOk(), - ...(r.isOk() ? r.value : r.error), - }, - ] as const; - }), + return [ + c.chain.key, + status === 'healthy' + ? { status: 'up' } + : { + status: 'down', + error: status.name, + message: status.message, + }, + ] as const; + }), ), ); - const healthy = Object.values(statuses).every((r) => r.healthy); + const healthy = Object.values(statuses).every((r) => r.status === 'up'); return this.getStatus(key, healthy, statuses); }