iachat/app/jobs/webhook_job.rb
Gabriel Jablonski 3c2d535de2
feat(webhook): retry job on 404 (#179)
* feat(webhook): retry job on 404

* feat(webhook): enhance retry logic for 404 errors and update message status

* feat(webhook): update supported message events to use dynamic error handling

* chore: refactor logic

* feat(webhook): simplify RetriableError initialization and improve error handling for 404 responses
2026-01-01 20:42:16 -03:00

18 lines
664 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)
Webhooks::Trigger.execute(url, payload, webhook_type)
end
end