Files
leadchat/app/jobs/webhooks/facebook_events_job.rb
Shivam Mishra 3760f206e8 fix: mutex timeout and error handling (#8770)
Fixes the follow cases 
- The ensure block released the lock even on LockAcquisitionError
- Custom timeout was not allowed

This also refactored the with_lock method, now the key has to be constructed in the parent function itself

Co-authored-by: Sojan Jose <sojan@pepalo.com>
2024-01-24 14:18:21 +04:00

18 lines
534 B
Ruby

class Webhooks::FacebookEventsJob < MutexApplicationJob
queue_as :default
retry_on LockAcquisitionError, wait: 1.second, attempts: 8
def perform(message)
response = ::Integrations::Facebook::MessageParser.new(message)
key = format(::Redis::Alfred::FACEBOOK_MESSAGE_MUTEX, sender_id: response.sender_id, recipient_id: response.recipient_id)
with_lock(key) do
process_message(response)
end
end
def process_message(response)
::Integrations::Facebook::MessageCreator.new(response).perform
end
end