Skip to content

Commit

Permalink
Merge pull request #195 from sotatek-dev/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Sotatek-TanHoang authored Oct 22, 2024
2 parents 665bd80 + 46423a8 commit 0df98f0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
15 changes: 8 additions & 7 deletions src/modules/crawler/batch.tokenprice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ export class BatchJobGetPriceToken {
private readonly tokenPriceRepository: TokenPriceRepository,
private loggerService: LoggerService,
) {}
private readonly apiKey = this.configService.get(EEnvKey.COINMARKET_KEY);
private readonly apiUrl = this.configService.get(EEnvKey.COINMARKET_URL);
private readonly headers = {
headers: {
'X-CMC_PRO_API_KEY': this.apiKey,
},
};
private readonly logger = this.loggerService.getLogger('CRAWL_TOKEN_PRICE');

public async handleCrawlInterval() {
Expand All @@ -32,13 +39,7 @@ export class BatchJobGetPriceToken {
}
}
public async handleGetPriceToken() {
const apiKey = this.configService.get(EEnvKey.COINMARKET_KEY);
const apiUrl = this.configService.get(EEnvKey.COINMARKET_URL);
const headers = {
'X-CMC_PRO_API_KEY': apiKey,
};

const result = await axios.get(apiUrl, { headers });
const result = await axios.get(this.apiUrl, this.headers);

const minaNewPrice = String(result.data.data?.[ECoinMarketCapTokenId.MINA]?.quote?.USD.price).valueOf();
const ethNewPrice = String(result.data.data?.[ECoinMarketCapTokenId.ETH]?.quote?.USD.price).valueOf();
Expand Down
19 changes: 11 additions & 8 deletions src/modules/crawler/crawler.console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ export class CrawlerConsole {
})
async handleCrawlETHBridge() {
const safeBlock = +this.configService.get(EEnvKey.ETH_TOKEN_BRIDGE_ADDRESS);
try {
while (true) {
while (true) {
try {
await this.blockchainEVMCrawler.handleEventCrawlBlock(safeBlock);
} catch (error) {
this.logger.error(error);
} finally {
await sleep(15);
}
} catch (error) {
this.logger.error(error);
}
}

Expand Down Expand Up @@ -84,6 +85,7 @@ export class CrawlerConsole {
await this.queueService.handleQueueJob<IUnlockToken>(EQueueName.EVM_SENDER_QUEUE, async (data: IUnlockToken) => {
const result = await this.senderEVMBridge.handleUnlockEVM(data.eventLogId);
if (result.error) {
// catch in queueService
throw result.error;
}
});
Expand All @@ -94,13 +96,14 @@ export class CrawlerConsole {
description: 'crawl Mina Bridge Contract',
})
async handleCrawlMinaBridge() {
try {
while (true) {
while (true) {
try {
await this.scBridgeMinaCrawler.handleEventCrawlBlock();
} catch (error) {
this.logger.error(error);
} finally {
await sleep(15);
}
} catch (error) {
this.logger.error(error);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/crawler/job-unlock.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export class JobUnlockProvider {

public async handleJob() {
await Promise.all([
this.getPendingTx(true),
this.getPendingTx(false),
// this.getPendingTx(true),
// this.getPendingTx(false),
this.tokenPriceCrawler.handleCrawlInterval(),
]);
}
Expand Down

0 comments on commit 0df98f0

Please sign in to comment.