Class: WCC::Contentful::WebhookController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- WCC::Contentful::WebhookController
- Includes:
- ServiceAccessors
- Defined in:
- app/controllers/wcc/contentful/webhook_controller.rb
Overview
The WebhookController is mounted by the WCC::Contentful::Engine to receive webhook events from Contentful. It passes these webhook events to the jobs configured in WCC::Contentful::Configuration#webhook_jobs
Constant Summary
Constants included from ServiceAccessors
Instance Method Summary collapse
Instance Method Details
#receive ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/wcc/contentful/webhook_controller.rb', line 19 def receive event = params.require('webhook').permit! event.require('sys').require(%w[id type]) event = event.to_h # Immediately update the store, we may update again later using DelayedSyncJob. store.index(event) if store.respond_to?(:index) jobs.each do |job| begin if job.respond_to?(:perform_later) job.perform_later(event) elsif job.respond_to?(:call) job.call(event) else Rails.logger.error "Misconfigured webhook job: #{job} does not respond to " \ ':perform_later or :call' end rescue StandardError => e Rails.logger.error "Error in job #{job}: #{e}" end end end |