From 6ce158ccc1370b514373dde16291140f11127e04 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Thu, 1 Aug 2024 13:11:01 +0300 Subject: [PATCH] Add retries for getting pub-trades if returns not array --- .../sync/transaction.tax.report/index.js | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/workers/loc.api/sync/transaction.tax.report/index.js b/workers/loc.api/sync/transaction.tax.report/index.js index c0b662df..31e3e44b 100644 --- a/workers/loc.api/sync/transaction.tax.report/index.js +++ b/workers/loc.api/sync/transaction.tax.report/index.js @@ -1,5 +1,7 @@ 'use strict' +const { setTimeout } = require('node:timers/promises') + const INTERRUPTER_NAMES = require( 'bfx-report/workers/loc.api/interrupter/interrupter.names' ) @@ -460,28 +462,31 @@ class TransactionTaxReport { const getDataFn = this.rService[this.SYNC_API_METHODS.PUBLIC_TRADES] .bind(this.rService) - const { res } = await this.getDataFromApi({ - getData: (s, args) => getDataFn(args), - args, - callerName: 'TRANSACTION_TAX_REPORT', - eNetErrorAttemptsTimeframeMin: 10, - eNetErrorAttemptsTimeoutMs: 10000, - interrupter - }) + for (let i = 0; i < 6; i += 1) { + const { res } = await this.getDataFromApi({ + getData: (s, args) => getDataFn(args), + args, + callerName: 'TRANSACTION_TAX_REPORT', + eNetErrorAttemptsTimeframeMin: 10, + eNetErrorAttemptsTimeoutMs: 10000, + interrupter + }) - const pubTrades = Array.isArray(res) - ? res - : [] + if (isTestEnv) { + /* + * Need to reverse pub-trades array for test env + * as mocked test server return data in desc order + */ + return res.reverse() + } + if (Array.isArray(res)) { + return res + } - if (isTestEnv) { - /* - * Need to reverse pub-trades array for test env - * as mocked test server return data in desc order - */ - return pubTrades.reverse() + await setTimeout(10000) } - return pubTrades + return [] } async #updateExactUsdValueInColls (trxs) {