Skip to content

Commit

Permalink
Merge pull request #288 from Giveth/staging
Browse files Browse the repository at this point in the history
Fix connecting bull to redis
  • Loading branch information
mohammadranjbarz authored Jan 6, 2022
2 parents fc72797 + f32606d commit 5af94c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/analytics/segmentQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { sleep } from '../utils/utils';
import { redisConfig } from '../redis';
const analytics = getAnalytics();

const sendSegmentEventQueue = new Bull('send-segment-event', redisConfig);
const sendSegmentEventQueue = new Bull('send-segment-event', {
redis: redisConfig,
});

const numberOfVerifyDonationConcurrentJob = 1;

Expand Down
17 changes: 13 additions & 4 deletions src/services/syncDonationsWithNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ import Bull from 'bull';
import config from '../config';
import { redisConfig } from '../redis';

const verifyDonationsQueue = new Bull('verify-donations-queue', redisConfig);
const verifyDonationsQueue = new Bull('verify-donations-queue', {
redis: redisConfig,
});
const TWO_MINUTES = 1000 * 60 * 2;
setInterval(async () => {
const verifyDonationsQueueCount = await verifyDonationsQueue.count();
console.log(`Verify donations job queues count:`, {
verifyDonationsQueueCount,
});
}, TWO_MINUTES);

// As etherscan free plan support 5 request per second I think it's better the concurrent jobs should not be
// more than 5 with free plan https://etherscan.io/apis
Expand Down Expand Up @@ -38,17 +47,17 @@ const addJobToCheckPendingDonationsWithNetwork = async () => {
},
select: ['id'],
});
if (donations.length === 0) {
console.log('There is no pending donation to check with network');
}
console.log('Pending donations to be check', donations.length);
donations.forEach(donation => {
console.log('Add pending donation to queue', { donationId: donation.id });
verifyDonationsQueue.add({
donationId: donation.id,
});
});
};

function processVerifyDonationsJobs() {
console.log('processVerifyDonationsJobs() has been called');
verifyDonationsQueue.process(
numberOfVerifyDonationConcurrentJob,
async (job, done) => {
Expand Down

0 comments on commit 5af94c7

Please sign in to comment.