Class: Spree::WebhookEventSubscriber
- Inherits:
-
Subscriber
- Object
- Subscriber
- Spree::WebhookEventSubscriber
- Defined in:
- app/subscribers/spree/webhook_event_subscriber.rb
Overview
Listens to Spree events and queues webhook deliveries for enabled endpoints.
This subscriber listens to all Spree events and for each event, finds all enabled webhook endpoints that are subscribed to that event and queues a delivery job for each one.
The event payload is passed through directly without transformation. Events should already be serialized by the EventSerializer.
Constant Summary collapse
- NON_DELIVERABLE_EVENTS =
Admin auth events carry live credentials (password reset tokens) and have no legitimate external consumer — core delivers those emails itself. Never forward them to webhook endpoints, including '*' subscriptions.
%w[admin_user.password_reset_requested].freeze
Instance Method Summary collapse
Instance Method Details
#handle(event) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/subscribers/spree/webhook_event_subscriber.rb', line 25 def handle(event) return unless Spree::Api::Config.webhooks_enabled return if event.store_id.blank? return if NON_DELIVERABLE_EVENTS.include?(event.name) # Only load the columns we need for matching and delivery endpoints = Spree::WebhookEndpoint .enabled .where(store_id: event.store_id) .select(:id, :subscriptions) endpoints.each do |endpoint| next unless endpoint.subscribed_to?(event.name) queue_delivery(endpoint, event) end rescue StandardError => e Rails.logger.error "[Spree Webhooks] Error processing event: #{e.}" Rails.error.report(e) end |