This repository has been archived by the owner on Dec 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
F 594 fix stuck event handler queue #598
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4e495a1
Allow to delete multiple entries
mohammadranjbarz 73ab4fb
Add emails update and create to elastik search
mohammadranjbarz 43e0ec8
Remove jobs from queue if it doesnt remove after two minutes (prevent…
mohammadranjbarz 8cd0dca
Dont process jobs multiple times if the event status is Processed alr…
mohammadranjbarz e72c0b8
Merge branch 'develop' into f_594_fix_stock_event_handler_queue
mohammadranjbarz 0f636e8
Fix bug in check eventInDb status
mohammadranjbarz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
|
@@ -18,7 +19,7 @@ setInterval(async () => { | |
eventHandlerQueueCount, | ||
NewEventQueueCount, | ||
}); | ||
}, 1000 * 60 * 2); | ||
}, TWO_MINUTES); | ||
|
||
const removeEvent = async (app, event) => { | ||
const { id, transactionHash } = event; | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be eventInDb.status There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aminlatifi |
||
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 { | ||
|
@@ -181,6 +202,7 @@ const initEventHandlerQueue = app => { | |
processingError: e.toString(), | ||
}); | ||
} finally { | ||
clearTimeout(callDoneTimeout); | ||
done(); | ||
} | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,5 @@ | ||||||||||||
const defaultFeatherMongooseOptions = { | ||||||||||||
multi: ['patch'], | ||||||||||||
multi: ['patch', 'remove'], | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 feathers-giveth/src/blockchain/lib/eventHandlerQueue.js Lines 26 to 30 in f245076
|
||||||||||||
whitelist: [ | ||||||||||||
'$exists', | ||||||||||||
'$and', | ||||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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