iachat/app/jobs/webhook_job.rb

18 lines
737 B
Ruby

class WebhookJob < ApplicationJob
queue_as :medium
retry_on CustomExceptions::Webhook::RetriableError, wait: :polynomially_longer, attempts: 5
discard_on CustomExceptions::Webhook::RetriableError do |job, error|
payload = job.arguments[1]
webhook_type = job.arguments[2] || :account_webhook
Rails.logger.warn "Webhook retries exhausted for #{payload[:event]}: #{error.message}"
Webhooks::ErrorHandler.perform(payload, webhook_type, error)
end
# There are 3 types of webhooks, account, inbox and agent_bot
def perform(url, payload, webhook_type = :account_webhook, secret: nil, delivery_id: nil)
Webhooks::Trigger.execute(url, payload, webhook_type, secret: secret, delivery_id: delivery_id)
end
end