Class: Axn::Webhooks::Outbound::Emit
- Inherits:
-
Object
- Object
- Axn::Webhooks::Outbound::Emit
- Includes:
- Axn, VendorFacet
- Defined in:
- lib/axn/webhooks/outbound/emit.rb
Overview
Resolves an event's subscribers and enqueues one Deliver per target. Built as an Axn so an unknown event (a typo) is a loud, reported failure instead of today's silent no-op.
Instance Method Summary collapse
Methods included from VendorFacet
Instance Method Details
#call ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/axn/webhooks/outbound/emit.rb', line 59 def call config = Axn::Webhooks::Outbound.config type = config.wire_type(event) use_async = async? # Only the :auto path is a DEGRADED mode worth warning about — an explicit `async: false` # is the caller getting exactly what they asked for. warn_sync_fallback(type) if async.nil? && !use_async resolution = resolve_targets(config) report_rejections(resolution.rejections) if resolution.rejections.any? deliveries = [] failed = 0 resolution.subscribers.each do |subscriber| id = Envelope.new_id body = Envelope.build(id:, type:, data:) delivered = enqueue(use_async, url: subscriber.url, webhook_id: id, body:, event: type, vendor:, subscriber_id: subscriber.id) failed += 1 if delivered && !delivered.ok? deliveries << { webhook_id: id, url: subscriber.url, subscriber_id: subscriber.id } end expose(webhook_ids: deliveries.map { |d| d[:webhook_id] }, target_count: deliveries.size, failed_count: failed, deliveries:, rejected_count: resolution.rejections.size, rejected: resolution.rejections) end |