Class: Fosm::WebhookDeliveryJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/fosm/webhook_delivery_job.rb

Overview

Delivers webhook payloads to configured endpoints when FOSM events fire. Runs asynchronously after the transition completes.

Instance Method Summary collapse

Instance Method Details

#perform(record_type:, record_id:, event_name:, from_state:, to_state:, metadata: {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/jobs/fosm/webhook_delivery_job.rb', line 8

def perform(record_type:, record_id:, event_name:, from_state:, to_state:, metadata: {})
  subscriptions = Fosm::WebhookSubscription.for_event(record_type, event_name)
  return if subscriptions.none?

  payload = {
    event: event_name,
    record_type: record_type,
    record_id: record_id,
    from_state: from_state,
    to_state: to_state,
    fired_at: Time.current.iso8601,
    metadata: 
  }

  subscriptions.each do |subscription|
    deliver(subscription, payload)
  end
end