From a0e7df851a4dc39cb8ad8cf22e56ded2c7e87ce3 Mon Sep 17 00:00:00 2001 From: Kenneth Hoang Date: Tue, 10 Dec 2024 10:22:57 +0700 Subject: [PATCH] feat: add env for retry job unlock provider --- .env.example | 4 +++- src/config/config.module.ts | 1 + src/constants/env.constant.ts | 1 + src/modules/crawler/crawler.evmbridge.ts | 4 ++++ src/modules/crawler/crawler.minabridge.ts | 4 ++++ src/modules/crawler/job-unlock.provider.ts | 4 +++- 6 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 63f7d60..cc883d3 100644 --- a/.env.example +++ b/.env.example @@ -69,4 +69,6 @@ THIS_VALIDATOR_INDEX=1 BULL_MONITOR_PORT=3056 REDIS_HOST=local -REDIS_PORT=6361 \ No newline at end of file +REDIS_PORT=6361 +# how long to delay a failed job in job unlock provider (minutes). default to 1 hours +JOB_PROVIDER_BACKOFF_IN_MINUTES=60 \ No newline at end of file diff --git a/src/config/config.module.ts b/src/config/config.module.ts index 20655ff..f891936 100644 --- a/src/config/config.module.ts +++ b/src/config/config.module.ts @@ -63,6 +63,7 @@ const getEnvFile = () => { [EEnvKey.MINA_VALIDATOR_THRESHHOLD]: Joi.number().required(), // fee [EEnvKey.BASE_MINA_BRIDGE_FEE]: Joi.number().default(1 * Math.pow(10, 8)), + [EEnvKey.JOB_PROVIDER_BACKOFF_IN_MINUTES]: Joi.number().default(1 * 60), // default 1 hours }).custom(value => { value[EEnvKey.ETH_BRIDGE_START_BLOCK] = isNumber(value[EEnvKey.ETH_BRIDGE_START_BLOCK]) ? value[EEnvKey.ETH_BRIDGE_START_BLOCK] diff --git a/src/constants/env.constant.ts b/src/constants/env.constant.ts index 9d7f3ed..56aca8d 100644 --- a/src/constants/env.constant.ts +++ b/src/constants/env.constant.ts @@ -48,6 +48,7 @@ export enum EEnvKey { MINA_CRAWL_SAFE_BLOCK = 'MINA_CRAWL_SAFE_BLOCK', THIS_VALIDATOR_INDEX = 'THIS_VALIDATOR_INDEX', EVM_SAFE_BLOCK = 'SAFE_BLOCK', + JOB_PROVIDER_BACKOFF_IN_MINUTES = 'JOB_PROVIDER_BACKOFF_IN_MINUTES', } export enum EEnvironments { diff --git a/src/modules/crawler/crawler.evmbridge.ts b/src/modules/crawler/crawler.evmbridge.ts index 8001264..7dde7ee 100644 --- a/src/modules/crawler/crawler.evmbridge.ts +++ b/src/modules/crawler/crawler.evmbridge.ts @@ -154,6 +154,10 @@ export class BlockchainEVMCrawler { const currentConfig = await configRepo.findOneBy({}); assert(currentConfig, 'comomn config not exist'); const newTotalEthBurnt = new BigNumber(currentConfig.totalWethBurnt).plus(existLockTx.amountFrom).toString(); + + this.logger.info(`Current total burnt ${currentConfig.totalWethBurnt}`); + this.logger.info(`New total burnt ${newTotalEthBurnt}`); + await configRepo.update(currentConfig.id, { totalWethBurnt: newTotalEthBurnt }); return { success: true, diff --git a/src/modules/crawler/crawler.minabridge.ts b/src/modules/crawler/crawler.minabridge.ts index 7420e78..0442ca8 100644 --- a/src/modules/crawler/crawler.minabridge.ts +++ b/src/modules/crawler/crawler.minabridge.ts @@ -116,6 +116,10 @@ export class SCBridgeMinaCrawler { const currentConfig = await configRepo.findOneBy({}); assert(currentConfig, 'comomn config not exist'); const newTotalEthMinted = new BigNumber(currentConfig.totalWethMinted).plus(existLockTx.amountReceived).toString(); + + this.logger.info(`Current total minted ${currentConfig.totalWethMinted}`); + this.logger.info(`New total minted ${newTotalEthMinted}`); + await configRepo.update(currentConfig.id, { totalWethMinted: newTotalEthMinted }); return { success: true, diff --git a/src/modules/crawler/job-unlock.provider.ts b/src/modules/crawler/job-unlock.provider.ts index 577c804..ba05e35 100644 --- a/src/modules/crawler/job-unlock.provider.ts +++ b/src/modules/crawler/job-unlock.provider.ts @@ -88,7 +88,9 @@ export class JobUnlockProvider { // helpers private updateIntervalStatusForTxs(ids: number[], isSignatureFullFilled: boolean) { const payload: QueryDeepPartialEntity = {}; - const nextTime = getTimeInFutureInMinutes(60 * 5).toString(); + const nextTime = getTimeInFutureInMinutes( + this.configService.get(EEnvKey.JOB_PROVIDER_BACKOFF_IN_MINUTES)!, + ).toString(); const query: FindOptionsWhere = {}; if (isSignatureFullFilled) { payload.nextSendTxJobTime = nextTime;