class Airbrake::RemoteSettings

@api private
@since ?.?.?
When {#stop_polling} is called, the current config will be dumped to disk.
that it doesn’t wait on the result from the API call.
When {#poll} is called, it will try to load remote settings from disk, so
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.
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, &block)

Returns:
  • (Airbrake::RemoteSettings) -

Other tags:
    Yieldparam: data -

Other tags:
    Yield: -

Parameters:
  • project_id (Integer) --
def self.poll(project_id, &block)
  new(project_id, &block).poll
end

def dump_config

def dump_config
  config_dir = File.dirname(CONFIG_DUMP_PATH)
  Dir.mkdir(config_dir) unless File.directory?(config_dir)
  File.write(CONFIG_DUMP_PATH, JSON.dump(@data.to_h))
end

def fetch_config

def fetch_config
  response = nil
  begin
    response = Net::HTTP.get(URI(@data.config_route))
  rescue StandardError => ex
    logger.error(ex)
    return {}
  end
  # AWS S3 API returns XML when request is not valid. In this case we just
  # print the returned body and exit the method.
  if response.start_with?('<?xml ')
    logger.error(response)
    return {}
  end
  json = nil
  begin
    json = JSON.parse(response)
  rescue JSON::ParserError => ex
    logger.error(ex)
    return {}
  end
  json
end

def initialize(project_id, &block)

Other tags:
    Yieldparam: data -

Other tags:
    Yield: -

Parameters:
  • project_id (Integer) --
def initialize(project_id, &block)
  @data = SettingsData.new(project_id, {})
  @block = block
  @poll = nil
end

def load_config

def load_config
  config_dir = File.dirname(CONFIG_DUMP_PATH)
  Dir.mkdir(config_dir) unless File.directory?(config_dir)
  return unless File.exist?(CONFIG_DUMP_PATH)
  config = File.read(CONFIG_DUMP_PATH)
  @data.merge!(JSON.parse(config))
end

def poll

Returns:
  • (self) -
def poll
  @poll ||= Thread.new do
    begin
      load_config
    rescue StandardError => ex
      logger.error("#{LOG_LABEL} config loading failed: #{ex}")
    end
    @block.call(@data)
    loop do
      @block.call(@data.merge!(fetch_config))
      sleep(@data.interval)
    end
  end
  self
end

def stop_polling

Returns:
  • (void) -
def stop_polling
  @poll.kill if @poll
  begin
    dump_config
  rescue StandardError => ex
    logger.error("#{LOG_LABEL} config dumping failed: #{ex}")
  end
end