Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

F 594 fix stuck event handler queue #598

Merged
merged 6 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/auditLog/feathersElasticSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const configureAuditLog = app => {
setAuditLogToFeathersService({ app, serviceName: 'donations' });
setAuditLogToFeathersService({ app, serviceName: 'pledgeAdmins' });
setAuditLogToFeathersService({ app, serviceName: 'events' });
setAuditLogToFeathersService({ app, serviceName: 'emails' });
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related to #597, we add emails to elastik search it help us to better debug

};

module.exports = {
Expand Down
24 changes: 23 additions & 1 deletion src/blockchain/lib/eventHandlerQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { EventStatus } = require('../../models/events.model');

const handleEventQueue = new Queue('eventHandler', { redis: config.get('redis') });
const pendingEventQueue = new Queue('NewEventQueue', { redis: config.get('redis') });
const TWO_MINUTES = 1000 * 60 * 2;

setInterval(async () => {
const eventHandlerQueueCount = await handleEventQueue.count();
Expand All @@ -18,7 +19,7 @@ setInterval(async () => {
eventHandlerQueueCount,
NewEventQueueCount,
});
}, 1000 * 60 * 2);
}, TWO_MINUTES);

const removeEvent = async (app, event) => {
const { id, transactionHash } = event;
Expand Down Expand Up @@ -155,16 +156,36 @@ const initEventHandlerQueue = app => {

handleEventQueue.process(1, async (job, done) => {
const { event } = job.data;
const callDoneTimeout = setTimeout(() => {
logger.error('The event handler didnt respond, call done() to prevent stocking queue');
done();
}, TWO_MINUTES);

try {
const remainingEventsInQueue = await handleEventQueue.count();
const handler = handlers[event.event];

logger.info('Handling Event: ', {
remainingEventsInQueue,
event: event.event,
transactionHash: event.transactionHash,
status: event.status,
transactionIndex: event.transactionIndex,
logIndex: event.logIndex,
_id: event._id,
});
const eventInDb = await eventService.get(event._id);
if (eventInDb === EventStatus.PROCESSED) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be eventInDb.status

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aminlatifi
You are right, changed

logger.info('Event is already processed, so dont need to handle again', {
event: event.event,
_id: event._id,
transactionHash: event.transactionHash,
transactionIndex: event.transactionIndex,
});
clearTimeout(callDoneTimeout);
done();
return;
}
if (typeof handler === 'function') {
await handler(event);
} else {
Expand All @@ -181,6 +202,7 @@ const initEventHandlerQueue = app => {
processingError: e.toString(),
});
} finally {
clearTimeout(callDoneTimeout);
done();
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/services/serviceCommons.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const defaultFeatherMongooseOptions = {
multi: ['patch'],
multi: ['patch', 'remove'],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We get an error in this line because we have blocked multiple delete (I saw it when I was reading the logs to fix this bug), so added remove to the whitelist

await eventService.remove(null, {
query: { id, transactionHash, status: { $in: [EventStatus.PENDING, EventStatus.WAITING] } },
});

whitelist: [
'$exists',
'$and',
Expand Down