Skip to content
Permalink
Browse files

remove concurrency and only update status after push message to queue

  • Loading branch information...
khaihkd committed Jul 24, 2018
1 parent c6c56c2 commit bd4d78c5eca8054caf1a11841ae82071904b7b3c
Showing with 11 additions and 10 deletions.
  1. +1 −6 queues/index.js
  2. +10 −4 queues/transaction.js
@@ -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;
@@ -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 })

@@ -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 }
)

}
}

0 comments on commit bd4d78c

Please sign in to comment.
You can’t perform that action at this time.