Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send ipc messages when trx tax report is ready #397

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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