Skip to content

Commit

Permalink
Merge pull request #212 from sotatek-dev/feat/env-job-provider
Browse files Browse the repository at this point in the history
feat: add env for retry job unlock provider
  • Loading branch information
Sotatek-HauTran3 authored Dec 10, 2024
2 parents 919bb3b + a0e7df8 commit 0157404
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ THIS_VALIDATOR_INDEX=1

BULL_MONITOR_PORT=3056
REDIS_HOST=local
REDIS_PORT=6361
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
1 change: 1 addition & 0 deletions src/config/config.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions src/constants/env.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/modules/crawler/crawler.evmbridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/modules/crawler/crawler.minabridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/modules/crawler/job-unlock.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ export class JobUnlockProvider {
// helpers
private updateIntervalStatusForTxs(ids: number[], isSignatureFullFilled: boolean) {
const payload: QueryDeepPartialEntity<EventLog> = {};
const nextTime = getTimeInFutureInMinutes(60 * 5).toString();
const nextTime = getTimeInFutureInMinutes(
this.configService.get<number>(EEnvKey.JOB_PROVIDER_BACKOFF_IN_MINUTES)!,
).toString();
const query: FindOptionsWhere<EventLog> = {};
if (isSignatureFullFilled) {
payload.nextSendTxJobTime = nextTime;
Expand Down

0 comments on commit 0157404

Please sign in to comment.