From b669302e1d831244042fd8df75a5dd7fe1981810 Mon Sep 17 00:00:00 2001 From: phamphong9981 Date: Mon, 28 Aug 2023 15:17:25 +0700 Subject: [PATCH 1/3] feat: health check job --- ci/config.json.ci | 3 ++ config.json | 3 ++ src/common/constant.ts | 8 +++ .../api-gateways/api_gateway.service.ts | 1 + .../api-gateways/services-manager.service.ts | 49 ++++++++++++++++++ .../manager/services-manager.service.ts | 50 +++++++++++++++++++ 6 files changed, 114 insertions(+) create mode 100644 src/services/api-gateways/services-manager.service.ts create mode 100644 src/services/manager/services-manager.service.ts diff --git a/ci/config.json.ci b/ci/config.json.ci index b5937068d..9679aa57c 100644 --- a/ci/config.json.ci +++ b/ci/config.json.ci @@ -188,5 +188,8 @@ "jobReassignMsgIndexToEvent": { "millisecondCrawl": 1000, "blocksPerCall": 100 + }, + "servicesManager": { + "healthCheckLimit": 100 } } diff --git a/config.json b/config.json index b64430ef3..01134d467 100644 --- a/config.json +++ b/config.json @@ -188,5 +188,8 @@ "jobReassignMsgIndexToEvent": { "millisecondCrawl": 1000, "blocksPerCall": 100 + }, + "servicesManager": { + "healthCheckLimit": 100 } } diff --git a/src/common/constant.ts b/src/common/constant.ts index 9ce82979a..bc47f0bf5 100644 --- a/src/common/constant.ts +++ b/src/common/constant.ts @@ -274,6 +274,14 @@ export const SERVICE = { key: 'CrawlIBCAppService', name: 'v1.CrawlIBCAppService', }, + ServicesManager: { + key: 'ServicesManager', + name: 'v1.ServicesManager', + HealthCheck: { + key: 'HealthCheck', + path: 'v1.ServicesManager.HealthCheck', + }, + }, }, }; diff --git a/src/services/api-gateways/api_gateway.service.ts b/src/services/api-gateways/api_gateway.service.ts index ef301f26c..2fc04c4af 100644 --- a/src/services/api-gateways/api_gateway.service.ts +++ b/src/services/api-gateways/api_gateway.service.ts @@ -25,6 +25,7 @@ import { bullBoardMixin } from '../../mixins/bullBoard/bullBoard.mixin'; 'v2.graphql.*', 'v2.statistics.getDashboardStatisticsByChainId', 'v2.statistics.getTopAccountsByChainId', + 'v1.services-manager.*', ], }, { diff --git a/src/services/api-gateways/services-manager.service.ts b/src/services/api-gateways/services-manager.service.ts new file mode 100644 index 000000000..bfbb78b31 --- /dev/null +++ b/src/services/api-gateways/services-manager.service.ts @@ -0,0 +1,49 @@ +import { Get, Service } from '@ourparentcenter/moleculer-decorators-extended'; +import { Context, ServiceBroker } from 'moleculer'; +import networks from '../../../network.json' assert { type: 'json' }; +import BaseService from '../../base/base.service'; + +@Service({ + name: 'services-manager', + version: 1, +}) +export default class ServicesManagerService extends BaseService { + public constructor(public broker: ServiceBroker) { + super(broker); + } + + @Get('/health-check', { + name: 'healthCheck', + params: { + chainid: { + type: 'string', + optional: false, + enum: networks.map((network) => network.chainId), + }, + jobNames: { + type: 'array', + optional: false, + items: 'string', + }, + }, + }) + async healthCheck( + ctx: Context< + { + chainid: string; + jobNames: string[]; + }, + Record + > + ) { + const selectedChain = networks.find( + (network) => network.chainId === ctx.params.chainid + ); + return this.broker.call( + `v1.ServicesManager.HealthCheck@${selectedChain?.moleculerNamespace}`, + { + jobNames: ctx.params.jobNames, + } + ); + } +} diff --git a/src/services/manager/services-manager.service.ts b/src/services/manager/services-manager.service.ts new file mode 100644 index 000000000..8d3a2ab4d --- /dev/null +++ b/src/services/manager/services-manager.service.ts @@ -0,0 +1,50 @@ +import { + Action, + Service, +} from '@ourparentcenter/moleculer-decorators-extended'; +import { Context, ServiceBroker } from 'moleculer'; +import config from '../../../config.json' assert { type: 'json' }; +import BullableService from '../../base/bullable.service'; +import { BULL_JOB_NAME, SERVICE } from '../../common'; +import { BlockCheckpoint } from '../../models'; + +@Service({ + name: SERVICE.V1.ServicesManager.key, + version: 1, +}) +export default class ServicesManagerService extends BullableService { + public constructor(public broker: ServiceBroker) { + super(broker); + } + + @Action({ + name: SERVICE.V1.ServicesManager.HealthCheck.key, + params: { + jobNames: { + type: 'array', + optional: false, + items: 'string', + }, + }, + }) + public async actionHealthCheck(ctx: Context<{ jobNames: string[] }>) { + const { jobNames } = ctx.params; + const result: Record = {}; + const jobBlock = await BlockCheckpoint.query() + .where('job_name', BULL_JOB_NAME.CRAWL_BLOCK) + .first() + .throwIfNotFound(); + const jobsHeight = await BlockCheckpoint.query().whereIn( + 'job_name', + jobNames + ); + jobsHeight.forEach((job) => { + Object.assign(result, { + [job.job_name]: + jobBlock.height - job.height < + config.servicesManager.healthCheckLimit, + }); + }); + return result; + } +} From e541c2e73d9b6a364fc0984240379a513597f972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=E1=BA=A1m=20Th=C3=A0nh=20Phong?= <49814372+phamphong9981@users.noreply.github.com> Date: Mon, 28 Aug 2023 14:01:36 +0700 Subject: [PATCH 2/3] fix: cw721 activity missing from/to ( main ) (#294) * fix: cw721 activity missing from/to * fix: fill from/to cw721 activity * fix: fill from/to cw721 activity * fix: fill from/to cw721 activity * fix: fill from/to cw721 activity * refactor: code * fix: code * refactor: code --------- Co-authored-by: Vu Ngoc Quang --- src/models/event_attribute.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/models/event_attribute.ts b/src/models/event_attribute.ts index f67aad3b2..caed40064 100644 --- a/src/models/event_attribute.ts +++ b/src/models/event_attribute.ts @@ -96,6 +96,7 @@ export class EventAttribute extends BaseModel { GRANTER: 'granter', GRANTEE: 'grantee', FROM: 'from', + MINTER: 'minter', FEE: 'fee', FEE_PAYER: 'fee_payer', CLIENT_ID: 'client_id', From 845cfb127ffbb637a1000a25e6681214c5c9296a Mon Sep 17 00:00:00 2001 From: phamphong9981 Date: Tue, 5 Sep 2023 15:36:00 +0700 Subject: [PATCH 3/3] fix: rebase --- src/models/event_attribute.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/models/event_attribute.ts b/src/models/event_attribute.ts index caed40064..2f450dbe8 100644 --- a/src/models/event_attribute.ts +++ b/src/models/event_attribute.ts @@ -108,7 +108,6 @@ export class EventAttribute extends BaseModel { PORT_ID: 'port_id', COUNTERPARTY_PORT_ID: 'counterparty_port_id', COUNTERPARTY_CHANNEL_ID: 'counterparty_channel_id', - MINTER: 'minter', DATA_HEX: 'packet_data_hex', SEQUENCE: 'packet_sequence', SRC_PORT: 'packet_src_port',