* 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
41 lines
1.0 KiB
Ruby
41 lines
1.0 KiB
Ruby
class Webhooks::Trigger
|
|
def initialize(url, payload, webhook_type)
|
|
@url = url
|
|
@payload = payload
|
|
@webhook_type = webhook_type
|
|
end
|
|
|
|
def self.execute(url, payload, webhook_type)
|
|
new(url, payload, webhook_type).execute
|
|
end
|
|
|
|
def execute
|
|
perform_request
|
|
rescue RestClient::NotFound
|
|
Rails.logger.warn "Webhook returned 404: #{@url}"
|
|
raise CustomExceptions::Webhook::RetriableError, "Webhook endpoint not found: #{@url}"
|
|
rescue StandardError => e
|
|
Webhooks::ErrorHandler.perform(@payload, @webhook_type, e)
|
|
Rails.logger.warn "Exception: Invalid webhook URL #{@url} : #{e.message}"
|
|
end
|
|
|
|
private
|
|
|
|
def perform_request
|
|
RestClient::Request.execute(
|
|
method: :post,
|
|
url: @url,
|
|
payload: @payload.to_json,
|
|
headers: { content_type: :json, accept: :json },
|
|
timeout: webhook_timeout
|
|
)
|
|
end
|
|
|
|
def webhook_timeout
|
|
raw_timeout = GlobalConfig.get_value('WEBHOOK_TIMEOUT')
|
|
timeout = raw_timeout.presence&.to_i
|
|
|
|
timeout&.positive? ? timeout : 5
|
|
end
|
|
end
|