Class: ForemanWebhooks::DeliverWebhookJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/foreman_webhooks/deliver_webhook_job.rb

Instance Method Summary collapse

Instance Method Details

#humanized_nameObject



34
35
36
37
# File 'app/jobs/foreman_webhooks/deliver_webhook_job.rb', line 34

def humanized_name
  webhook = webhook_id && Webhook.unscoped.find_by(id: webhook_id)
  (webhook && (_('Deliver webhook %s') % webhook.name)) || _('Deliver webhook')
end

#perform(options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/jobs/foreman_webhooks/deliver_webhook_job.rb', line 7

def perform(options)
  webhook = Webhook.unscoped.find_by(id: options[:webhook_id])
  result = WebhookService.new(
    webhook: webhook,
    headers: options[:headers],
    url: options[:url],
    event_name: options[:event_name],
    payload: options[:payload]
  ).execute

  return unless result[:status] == :error

  raise [result[:http_status], result[:message]].compact.join(': ')
end

#webhook_idObject



30
31
32
# File 'app/jobs/foreman_webhooks/deliver_webhook_job.rb', line 30

def webhook_id
  arguments.first['webhook_id'] unless arguments.first.nil?
end