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

rework external loop of Orchestrator #27

Merged
merged 1 commit into from
Jul 3, 2019
Merged
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
28 changes: 14 additions & 14 deletions pushtx/orchestrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,21 @@ class Orchestrator {

Logger.info(`Block ${height} ${blockHash}`)

// Retrieve the transactions triggered by this block
let txs = await db.getActivatedScheduledTransactions(height)

while (txs && txs.length > 0) {
let rpcConnOk = true
let nbTxsPushed
let rpcConnOk = true

do {
nbTxsPushed = 0

// Retrieve the transactions triggered by this block
let txs = await db.getActivatedScheduledTransactions(height)
if (!(txs && txs.length > 0))
break

for (let tx of txs) {
let hasParentTx = (tx.schParentTxid != null) && (tx.schParentTxid != '')
let parentTx = null

// Check if previous transaction has been confirmed
if (hasParentTx) {
try {
Expand Down Expand Up @@ -132,20 +137,15 @@ class Orchestrator {
// Delete the transaction
try {
await db.deleteScheduledTransaction(tx.schTxid)
// Count the transaction as successfully processed
nbTxsPushed++
} catch(e) {
const msg = 'A problem was met while trying to delete a scheduled transaction'
Logger.error(e, `Orchestrator.onBlockHash() : ${msg}`)
}
}
}

// If a connection issue was detected, then stop the loop
if (!rpcConnOk)
break

// Check if more transactions have to be pushed
txs = await db.getActivatedScheduledTransactions(height)
}
} while (rpcConnOk && nbTxsPushed > 0)

} catch(e) {
Logger.error(e, 'Orchestrator.onBlockHash() : Error')
Expand Down