Class: Airbrake::RemoteSettings Private

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/airbrake-ruby/remote_settings.rb,
lib/airbrake-ruby/remote_settings/callback.rb,
lib/airbrake-ruby/remote_settings/settings_data.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

RemoteSettings polls the remote config of the passed project at fixed intervals. The fetched config is yielded as a callback parameter so that the invoker can define read config values. Supports proxies.

Examples:

Disable/enable error notifications based on the remote value

RemoteSettings.poll do |data|
  config.error_notifications = data.error_notifications?
end

Since:

  • v5.0.0

Defined Under Namespace

Classes: Callback, SettingsData

Constant Summary collapse

QUERY_PARAMS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Returns metadata to be attached to every GET request.

Returns:

  • (Hash{Symbol=>String})

    metadata to be attached to every GET request

Since:

  • v5.0.0

URI.encode_www_form(
  notifier_name: Airbrake::NOTIFIER_INFO[:name],
  notifier_version: Airbrake::NOTIFIER_INFO[:version],
  os: RUBY_PLATFORM,
  language: "#{RUBY_ENGINE}/#{RUBY_VERSION}".freeze,
).freeze
HTTP_OK =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Returns:

  • (String)

Since:

  • v5.0.0

'200'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Loggable

#logger

Constructor Details

#initialize(project_id, host) {|data| ... } ⇒ RemoteSettings

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of RemoteSettings.

Parameters:

  • project_id (Integer)

Yields:

  • (data)

Yield Parameters:

Since:

  • v5.0.0



42
43
44
45
46
47
48
# File 'lib/airbrake-ruby/remote_settings.rb', line 42

def initialize(project_id, host, &block)
  @data = SettingsData.new(project_id, {})
  @host = host
  @block = block
  @config = Airbrake::Config.instance
  @poll = nil
end

Class Method Details

.poll(project_id, host) {|data| ... } ⇒ Airbrake::RemoteSettings

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Polls remote config of the given project.

Parameters:

  • project_id (Integer)
  • host (String)

Yields:

  • (data)

Yield Parameters:

Returns:

Since:

  • v5.0.0



35
36
37
# File 'lib/airbrake-ruby/remote_settings.rb', line 35

def self.poll(project_id, host, &block)
  new(project_id, host, &block).poll
end

Instance Method Details

#pollself

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Polls remote config of the given project in background.

Returns:

  • (self)

Since:

  • v5.0.0



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/airbrake-ruby/remote_settings.rb', line 53

def poll
  @poll ||= Thread.new do
    @block.call(@data)

    loop do
      @block.call(@data.merge!(fetch_config))
      sleep(@data.interval)
    end
  end

  self
end

#stop_pollingvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Stops the background poller thread.

Since:

  • v5.0.0



69
70
71
# File 'lib/airbrake-ruby/remote_settings.rb', line 69

def stop_polling
  @poll.kill if @poll
end