Skip to content

Commit f24ec59

Browse files
committed
add parallel processing with cluster
1 parent 7285d2a commit f24ec59

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

queues/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ fs.readdirSync(__dirname)
1919
})
2020
.forEach(function (file) {
2121
let consumer = require(path.join(__dirname, file));
22-
q.process(consumer.name, consumer.task);
22+
if (consumer.name === 'newTransaction') {
23+
q.process(consumer.name, 6, consumer.task);
24+
25+
} else {
26+
q.process(consumer.name, consumer.task);
27+
}
2328
});
2429

2530
module.exports = q;

queues/transaction.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,21 @@ consumer.task = async function(job, done) {
3232
let tokenAmount = web3.utils.hexToNumberString(log.data) / 10 ** 18
3333
console.log(' - Found Transfer', tokenAmount, ' TOMO from: ', fromWallet, ' to: ', toWallet)
3434

35-
// Make new transaction
35+
let tran = await db.Transaction.findOne({hash: transaction.transactionHash, fromAccount: fromWallet})
36+
if (tran && tran.isProcess) {
37+
continue
38+
}
39+
40+
// Update or make new transaction
3641
await db.Transaction.findOneAndUpdate(
3742
{hash: transaction.transactionHash, fromAccount: fromWallet, toAccount: toWallet},
3843
{
3944
hash: transaction.transactionHash,
4045
block: transaction.blockNumber,
4146
fromAccount: fromWallet,
4247
toAccount: toWallet,
43-
tokenAmount: tokenAmount
48+
tokenAmount: tokenAmount,
49+
isProcess: true
4450
},
4551
{ upsert: true, new: true })
4652

0 commit comments

Comments
 (0)