class Airbrake::RemoteSettings
@api private
@since v5.0.0
end
config.error_notifications = data.error_notifications?
RemoteSettings.poll do |data|
@example Disable/enable error notifications based on the remote value
invoker can define read config values. Supports proxies.
intervals. The fetched config is yielded as a callback parameter so that the
RemoteSettings polls the remote config of the passed project at fixed
def self.poll(project_id, host, &block)
-
(Airbrake::RemoteSettings)
-
Other tags:
- Yieldparam: data -
Other tags:
- Yield: -
Parameters:
-
host
(String
) -- -
project_id
(Integer
) --
def self.poll(project_id, host, &block) new(project_id, host, &block).poll end
def build_config_uri
def build_config_uri uri = URI(@data.config_route(@host)) uri.query = QUERY_PARAMS uri end
def build_https(uri)
def build_https(uri) Net::HTTP.new(uri.host, uri.port, *proxy_params).tap do |https| https.use_ssl = uri.is_a?(URI::HTTPS) if @config.timeout https.open_timeout = @config.timeout https.read_timeout = @config.timeout end end end
def fetch_config
def fetch_config uri = build_config_uri https = build_https(uri) req = Net::HTTP::Get.new(uri.request_uri) response = nil begin response = https.request(req) rescue StandardError => ex reason = "#{LOG_LABEL} HTTP error: #{ex}" logger.error(reason) return {} end unless response.code == HTTP_OK logger.error(response.body) return {} end json = nil begin json = JSON.parse(response.body) rescue JSON::ParserError => ex logger.error(ex) return {} end json end
def initialize(project_id, host, &block)
- Yieldparam: data -
Other tags:
- Yield: -
Parameters:
-
project_id
(Integer
) --
def initialize(project_id, host, &block) @data = SettingsData.new(project_id, {}) @host = host @block = block @config = Airbrake::Config.instance @poll = nil end
def poll
-
(self)
-
def poll @poll ||= Thread.new do @block.call(@data) loop do @block.call(@data.merge!(fetch_config)) sleep(@data.interval) end end self end
def proxy_params
def proxy_params return unless @config.proxy.key?(:host) [@config.proxy[:host], @config.proxy[:port], @config.proxy[:user], @config.proxy[:password]] end
def stop_polling
-
(void)
-
def stop_polling @poll.kill if @poll end