Skip to content

Commit

Permalink
Merge pull request #397 from ZIMkaRU/feature/add-ipc-messages-when-tr…
Browse files Browse the repository at this point in the history
…x-tax-report-is-ready

Send ipc messages when trx tax report is ready
  • Loading branch information
ezewer authored Jul 25, 2024
2 parents ee25929 + eb0d587 commit 42a6a5d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
3 changes: 3 additions & 0 deletions workers/loc.api/process.message.manager/process.messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
33 changes: 28 additions & 5 deletions workers/loc.api/sync/transaction.tax.report/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const depsTypes = (TYPES) => [
TYPES.WSEventEmitterFactory,
TYPES.Logger,
TYPES.InterrupterFactory,
TYPES.CurrencyConverter
TYPES.CurrencyConverter,
TYPES.ProcessMessageManager
]
class TransactionTaxReport {
constructor (
Expand All @@ -50,7 +51,8 @@ class TransactionTaxReport {
wsEventEmitterFactory,
logger,
interrupterFactory,
currencyConverter
currencyConverter,
processMessageManager
) {
this.dao = dao
this.authenticator = authenticator
Expand All @@ -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)
Expand All @@ -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
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
)
}
}

Expand Down

0 comments on commit 42a6a5d

Please sign in to comment.