Skip to content

Commit

Permalink
remove concurrency and only update status after push message to queue
Browse files Browse the repository at this point in the history
  • Loading branch information
khaihkd committed Jul 24, 2018
1 parent c6c56c2 commit bd4d78c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
7 changes: 1 addition & 6 deletions queues/index.js
Expand Up @@ -19,12 +19,7 @@ fs.readdirSync(__dirname)
})
.forEach(function (file) {
let consumer = require(path.join(__dirname, file));
if (consumer.name === 'newTransaction') {
q.process(consumer.name, 6, consumer.task);

} else {
q.process(consumer.name, consumer.task);
}
q.process(consumer.name, consumer.task);
});

module.exports = q;
14 changes: 10 additions & 4 deletions queues/transaction.js
Expand Up @@ -45,8 +45,7 @@ consumer.task = async function(job, done) {
block: transaction.blockNumber,
fromAccount: fromWallet,
toAccount: toWallet,
tokenAmount: tokenAmount,
isProcess: true
tokenAmount: tokenAmount
},
{ upsert: true, new: true })

Expand All @@ -55,10 +54,17 @@ consumer.task = async function(job, done) {

const q = require('./index')
await q.create('addAmountToWallet', {toWallet: toWallet, tokenAmount: tokenAmount})
.priority('high').removeOnComplete(true).save()
.attempts(5).backoff({delay: 10000})
.priority('critical').removeOnComplete(true).save()

await q.create('subAmountFromWallet', {fromWallet: fromWallet, tokenAmount: tokenAmount})
.priority('high').removeOnComplete(true).save()
.attempts(5).backoff({delay: 10000})
.priority('critical').removeOnComplete(true).save()

await db.Transaction.findOneAndUpdate(
{hash: transaction.transactionHash, fromAccount: fromWallet, toAccount: toWallet},
{isProcess: true}, { upsert: true, new: true }
)

}
}
Expand Down

0 comments on commit bd4d78c

Please sign in to comment.