Skip to content
Permalink
Browse files

add parallel processing with cluster

  • Loading branch information...
khaihkd committed Jul 23, 2018
1 parent 7285d2a commit f24ec599d094951a97c5420faa0720d1661ff6df
Showing with 14 additions and 3 deletions.
  1. +6 −1 queues/index.js
  2. +8 −2 queues/transaction.js
@@ -19,7 +19,12 @@ fs.readdirSync(__dirname)
})
.forEach(function (file) {
let consumer = require(path.join(__dirname, file));
q.process(consumer.name, consumer.task);
if (consumer.name === 'newTransaction') {
q.process(consumer.name, 6, consumer.task);

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

module.exports = q;
@@ -32,15 +32,21 @@ consumer.task = async function(job, done) {
let tokenAmount = web3.utils.hexToNumberString(log.data) / 10 ** 18
console.log(' - Found Transfer', tokenAmount, ' TOMO from: ', fromWallet, ' to: ', toWallet)

// Make new transaction
let tran = await db.Transaction.findOne({hash: transaction.transactionHash, fromAccount: fromWallet})
if (tran && tran.isProcess) {
continue
}

// Update or make new transaction
await db.Transaction.findOneAndUpdate(
{hash: transaction.transactionHash, fromAccount: fromWallet, toAccount: toWallet},
{
hash: transaction.transactionHash,
block: transaction.blockNumber,
fromAccount: fromWallet,
toAccount: toWallet,
tokenAmount: tokenAmount
tokenAmount: tokenAmount,
isProcess: true
},
{ upsert: true, new: true })

0 comments on commit f24ec59

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