Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log webhook processing into the Rails logger #20

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Changes from all 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
14 changes: 8 additions & 6 deletions lib/munster/jobs/processing_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@

module Munster
class ProcessingJob < ActiveJob::Base
class WebhookPayloadInvalid < StandardError
end

def perform(webhook)
Rails.error.set_context(munster_handler_module_name: webhook.handler_module_name, **Munster.configuration.error_context)

webhook_details_for_logs = "Munster::ReceivedWebhook#%s (handler: %s)" % [webhook.id, webhook.handler]
webhook.with_lock do
return unless webhook.received?
unless webhook.received?
logger.info { "#{webhook_details_for_logs} is being processed in a different job or has been processed already, skipping." }
return
end
webhook.processing!
end

if webhook.handler.valid?(webhook.request)
logger.info { "#{webhook_details_for_logs} starting to process" }
webhook.handler.process(webhook)
webhook.processed! if webhook.processing?
logger.info { "#{webhook_details_for_logs} processed" }
else
e = WebhookPayloadInvalid.new("#{webhook.class} #{webhook.id} did not pass validation and was skipped")
Rails.error.report(e, handled: true, severity: :error)
logger.info { "#{webhook_details_for_logs} did not pass validation by the handler. Marking it `failed_validation`." }
webhook.failed_validation!
end
rescue => e
Expand Down