From 70d2f236a88b834e7766c2a393d892ccfc1adfd4 Mon Sep 17 00:00:00 2001 From: xiaoch05 Date: Wed, 21 Aug 2024 10:15:58 +0800 Subject: [PATCH] health check --- apollo/src/aggregation/aggregation.resolver.ts | 4 ++-- apollo/src/base/TransferServiceT1.ts | 1 + apollo/src/lnv2/lnv2.service.ts | 2 ++ apollo/src/lnv3/lnv3.service.ts | 3 ++- apollo/src/lnv3/source/super.service.ts | 12 ++++++------ apollo/src/tasks/tasks.service.ts | 8 +++++--- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/apollo/src/aggregation/aggregation.resolver.ts b/apollo/src/aggregation/aggregation.resolver.ts index 5d5ae334..04c3eea1 100644 --- a/apollo/src/aggregation/aggregation.resolver.ts +++ b/apollo/src/aggregation/aggregation.resolver.ts @@ -337,11 +337,11 @@ export class AggregationResolver { @Query() tasksHealthCheck(@Args('name') name: string) { const healthChecks = this.aggregationService.tasksHealthCheck(); - if (name !== null) { + if (name) { return [ { name: name, - callTimes: healthChecks[name], + callTimes: healthChecks.get(name), }, ]; } diff --git a/apollo/src/base/TransferServiceT1.ts b/apollo/src/base/TransferServiceT1.ts index 51b21dda..82b12221 100644 --- a/apollo/src/base/TransferServiceT1.ts +++ b/apollo/src/base/TransferServiceT1.ts @@ -91,6 +91,7 @@ export abstract class BaseServiceT1 { this.baseConfigure.fetchSendDataInterval, async () => { this.schedule(item, index); + return false; } ); }); diff --git a/apollo/src/lnv2/lnv2.service.ts b/apollo/src/lnv2/lnv2.service.ts index 492ff477..69dfdd6a 100644 --- a/apollo/src/lnv2/lnv2.service.ts +++ b/apollo/src/lnv2/lnv2.service.ts @@ -89,6 +89,7 @@ export class Lnv2Service implements OnModuleInit { index: 2 * index, }; this.schedule(item, indexInfo); + return false; } ); } @@ -103,6 +104,7 @@ export class Lnv2Service implements OnModuleInit { index: 2 * index + 1, }; this.schedule(item, indexInfo); + return false; } ); } diff --git a/apollo/src/lnv3/lnv3.service.ts b/apollo/src/lnv3/lnv3.service.ts index 72201d15..60a3f314 100644 --- a/apollo/src/lnv3/lnv3.service.ts +++ b/apollo/src/lnv3/lnv3.service.ts @@ -57,7 +57,7 @@ export class Lnv3Service implements OnModuleInit { this.fetchSendDataInterval, async () => { if (this.fetchCache[index].isSyncingHistory) { - return; + return true; } this.fetchCache[index].isSyncingHistory = true; await this.fetchProviderInfo(item, index); @@ -66,6 +66,7 @@ export class Lnv3Service implements OnModuleInit { await this.fetchStatus(item, index); await this.fetchWithdrawCacheStatus(item, index); this.fetchCache[index].isSyncingHistory = false; + return false; } ); }); diff --git a/apollo/src/lnv3/source/super.service.ts b/apollo/src/lnv3/source/super.service.ts index d36373f6..6637dd4b 100644 --- a/apollo/src/lnv3/source/super.service.ts +++ b/apollo/src/lnv3/source/super.service.ts @@ -14,7 +14,7 @@ export class Lnv3SuperService extends SourceService { .post(url, { query: query, variables: null, - }) + }, { timeout: 10000 }) .then((res) => res.data?.data?.lnv3TransferRecords); } @@ -28,7 +28,7 @@ export class Lnv3SuperService extends SourceService { .post(url, { query: query, variables: null, - }) + }, { timeout: 10000 }) .then((res) => res.data?.data?.lnv3RelayUpdateRecords); } async queryRelayStatus( @@ -41,7 +41,7 @@ export class Lnv3SuperService extends SourceService { .post(url, { query: query, variables: null, - }) + }, { timeout: 10000 }) .then((res) => res.data?.data?.lnv3RelayRecord); } async queryMultiRelayStatus( @@ -55,7 +55,7 @@ export class Lnv3SuperService extends SourceService { .post(url, { query: query, variables: null, - }) + }, { timeout: 10000 }) .then((res) => res.data?.data?.lnv3RelayRecords); } async batchQueryRelayStatus( @@ -69,7 +69,7 @@ export class Lnv3SuperService extends SourceService { .post(url, { query: query, variables: null, - }) + }, { timeout: 10000 }) .then((res) => res.data?.data?.lnv3RelayRecords); } async queryWithdrawStatus( @@ -82,7 +82,7 @@ export class Lnv3SuperService extends SourceService { .post(url, { query: query, variables: null, - }) + }, { timeout: 10000 }) .then((res) => res.data?.data?.lnv3TransferRecord); } } diff --git a/apollo/src/tasks/tasks.service.ts b/apollo/src/tasks/tasks.service.ts index fd67b096..6f78e27d 100644 --- a/apollo/src/tasks/tasks.service.ts +++ b/apollo/src/tasks/tasks.service.ts @@ -9,13 +9,15 @@ export class TasksService { constructor(private schedulerRegistry: SchedulerRegistry) {} - addInterval(name: string, milliseconds: number, callback: () => void) { + addInterval(name: string, milliseconds: number, callback: () => Promise) { this.logger.log(`new interval task added name:${name}, ms: ${milliseconds}`); this.healthChecks.set(name, 0); const interval = setInterval(async () => { const callTimes: number = this.healthChecks.get(name); - await callback(); - this.healthChecks.set(name, callTimes + 1); + const busy = await callback(); + if (!busy) { + this.healthChecks.set(name, callTimes + 1); + } }, milliseconds); this.schedulerRegistry.addInterval(name, interval); }