Class: Webhukhs::ProcessingJob
- Inherits:
-
ActiveJob::Base
- Object
- ActiveJob::Base
- Webhukhs::ProcessingJob
- Defined in:
- lib/webhukhs/jobs/processing_job.rb
Overview
Background job that validates and processes a persisted webhook.
Defined Under Namespace
Classes: InvalidWebhookArgument
Instance Method Summary collapse
-
#perform(webhook) ⇒ void
Runs webhook validation and processing lifecycle.
Instance Method Details
#perform(webhook) ⇒ void
This method returns an undefined value.
Runs webhook validation and processing lifecycle.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/webhukhs/jobs/processing_job.rb', line 22 def perform(webhook) raise InvalidWebhookArgument, "ProcessingJob received nil webhook argument" if webhook.nil? unless webhook.instance_of?(ReceivedWebhook) raise InvalidWebhookArgument, "ProcessingJob expected Webhukhs::ReceivedWebhook, got #{webhook.class}" end webhook_details_for_logs = "Webhukhs::ReceivedWebhook#%s (handler: %s)" % [webhook.id, webhook.handler] webhook.with_lock do 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 logger.info { "#{webhook_details_for_logs} did not pass validation by the handler. Marking it `failed_validation`." } webhook.failed_validation! end rescue webhook.error! if webhook.respond_to?(:error!) raise end |