class ActiveWebhook::Delivery::BaseAdapter
Attributes
response[RW]
Protected Class Methods
component_name()
click to toggle source
# File lib/active_webhook/delivery/base_adapter.rb, line 47 def self.component_name "delivery" end
Public Instance Methods
call()
click to toggle source
# File lib/active_webhook/delivery/base_adapter.rb, line 15 def call ensure_error_log_requirement_is_met! wrap_with_log do self.response = deliver! case status_code when 200 trace "Completed" when 410 trace "Receieved HTTP response code [410] for" subscription.destroy! else raise response.to_s end end rescue StandardError => e subscription.error_logs.create! raise e # propogate error so queuing adapter has a chance to retry end
max_errors_per_hour()
click to toggle source
# File lib/active_webhook/delivery/base_adapter.rb, line 11 def max_errors_per_hour @max_errors_per_hour.nil? ? component_configuration.max_errors_per_hour : @max_errors_per_hour end
status_code()
click to toggle source
# File lib/active_webhook/delivery/base_adapter.rb, line 37 def status_code raise NotImplementedError, "#deliver! must be implemented." end
topic()
click to toggle source
# File lib/active_webhook/delivery/base_adapter.rb, line 41 def topic subscription.topic end
Protected Instance Methods
decorate_log_msg(msg)
click to toggle source
# File lib/active_webhook/delivery/base_adapter.rb, line 86 def decorate_log_msg(msg) [ msg, "active webhook subscription #{subscription.id}", "with(key: #{topic.key}, version: #{topic.version})", "to url: #{hook.url} via #{self.class.name}" ].join(' ') end
deliver!()
click to toggle source
# File lib/active_webhook/delivery/base_adapter.rb, line 51 def deliver! raise NotImplementedError, "#deliver! must be implemented." end
ensure_error_log_requirement_is_met!()
click to toggle source
# File lib/active_webhook/delivery/base_adapter.rb, line 55 def ensure_error_log_requirement_is_met! if subscription.ensure_error_log_requirement_is_met! max_errors_per_hour trace "Disabled" end end
trace(msg, level = :info)
click to toggle source
# File lib/active_webhook/delivery/base_adapter.rb, line 80 def trace(msg, level = :info) ActiveWebhook.logger.send(level, decorate_log_msg(msg)) true end
wrap_with_log() { || ... }
click to toggle source
# File lib/active_webhook/delivery/base_adapter.rb, line 61 def wrap_with_log return if ActiveWebhook.disabled? trace("Skipped [subscription disabled]") and return if subscription.disabled? trace("Skipped [topic disabled]") and return if topic.disabled? trace "Initiated" trace "Payload [#{hook.to_h.ai}] for", :debug if ActiveWebhook.logger.level == 0 # log_payloads yield trace "Completed" true rescue StandardError => e trace "Failed to complete [#{e.message}]", :error raise e # propogate error so queuing adapter has a chance to retry end