diff --git a/workers/loc.api/process.message.manager/process.messages.js b/workers/loc.api/process.message.manager/process.messages.js index 07aaad4e3..7ba879a8e 100644 --- a/workers/loc.api/process.message.manager/process.messages.js +++ b/workers/loc.api/process.message.manager/process.messages.js @@ -7,6 +7,9 @@ module.exports = { READY_MIGRATIONS: 'ready:migrations', ERROR_MIGRATIONS: 'error:migrations', + READY_TRX_TAX_REPORT: 'ready:trx-tax-report', + ERROR_TRX_TAX_REPORT: 'error:trx-tax-report', + ALL_TABLE_HAVE_BEEN_CLEARED: 'all-tables-have-been-cleared', ALL_TABLE_HAVE_NOT_BEEN_CLEARED: 'all-tables-have-not-been-cleared', ALL_TABLE_HAVE_BEEN_REMOVED: 'all-tables-have-been-removed', diff --git a/workers/loc.api/sync/transaction.tax.report/index.js b/workers/loc.api/sync/transaction.tax.report/index.js index 0c5435d61..c0b662df4 100644 --- a/workers/loc.api/sync/transaction.tax.report/index.js +++ b/workers/loc.api/sync/transaction.tax.report/index.js @@ -35,7 +35,8 @@ const depsTypes = (TYPES) => [ TYPES.WSEventEmitterFactory, TYPES.Logger, TYPES.InterrupterFactory, - TYPES.CurrencyConverter + TYPES.CurrencyConverter, + TYPES.ProcessMessageManager ] class TransactionTaxReport { constructor ( @@ -50,7 +51,8 @@ class TransactionTaxReport { wsEventEmitterFactory, logger, interrupterFactory, - currencyConverter + currencyConverter, + processMessageManager ) { this.dao = dao this.authenticator = authenticator @@ -64,6 +66,7 @@ class TransactionTaxReport { this.logger = logger this.interrupterFactory = interrupterFactory this.currencyConverter = currencyConverter + this.processMessageManager = processMessageManager this.tradesModel = this.syncSchema.getModelsMap() .get(this.ALLOWED_COLLS.TRADES) @@ -75,14 +78,22 @@ class TransactionTaxReport { .verifyRequestUser({ auth }) const _args = { auth: user, params } + const trxTaxReportPromise = this.getTransactionTaxReport(_args) + this.wsEventEmitterFactory() .emitTrxTaxReportGenerationInBackgroundToOne(() => { - return this.getTransactionTaxReport(_args) + return trxTaxReportPromise }, user) .then(() => {}, (err) => { this.logger.error(`TRX_TAX_REPORT_GEN_FAILED: ${err.stack || err}`) }) + trxTaxReportPromise.catch(() => { + this.processMessageManager.sendState( + this.processMessageManager.PROCESS_MESSAGES.ERROR_TRX_TAX_REPORT + ) + }) + return true } @@ -458,15 +469,19 @@ class TransactionTaxReport { 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() + return pubTrades.reverse() } - return res + return pubTrades } async #updateExactUsdValueInColls (trxs) { @@ -545,6 +560,14 @@ class TransactionTaxReport { }, user ) + + if (state !== PROGRESS_STATES.GENERATION_COMPLETED) { + return + } + + this.processMessageManager.sendState( + this.processMessageManager.PROCESS_MESSAGES.READY_TRX_TAX_REPORT + ) } }