Class: LaunchDarkly::Impl::DataSource::PollingProcessor Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ldclient-rb/impl/data_source/polling.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.

Since:

  • 5.5.0

Instance Method Summary collapse

Constructor Details

#initialize(config, requestor) ⇒ PollingProcessor

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 PollingProcessor.

Since:

  • 5.5.0



14
15
16
17
18
19
20
21
22
# File 'lib/ldclient-rb/impl/data_source/polling.rb', line 14

def initialize(config, requestor)
  @config = config
  @requestor = requestor
  @initialized = Concurrent::AtomicBoolean.new(false)
  @started = Concurrent::AtomicBoolean.new(false)
  @ready = Concurrent::Event.new
  @retry_state = Impl::RetryState.for_polling(@config.poll_interval, @config.logger)
  @task = Impl::RepeatingTask.new(-> { @retry_state.next_delay }, 0, -> { self.poll }, @config.logger, 'LD/PollingDataSource')
end

Instance Method Details

#initialized? ⇒ Boolean

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:

  • (Boolean)

Since:

  • 5.5.0



24
25
26
# File 'lib/ldclient-rb/impl/data_source/polling.rb', line 24

def initialized?
  @initialized.value
end

#poll ⇒ Object

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.

Since:

  • 5.5.0



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ldclient-rb/impl/data_source/polling.rb', line 39

def poll
  begin
    all_data, headers = request_all_data
    DataSource.record_environment_id(@config.data_source_update_sink, headers)
    newly_initialized = false
    if all_data
      update_sink_or_data_store.init(all_data)
      newly_initialized = @initialized.make_true
    end
    @retry_state.record_success
    @config.data_source_update_sink&.update_status(LaunchDarkly::Interfaces::DataSource::Status::VALID, nil)

    if newly_initialized
      @config.logger.info { "[LDClient] Polling connection initialized" }
      @ready.set
    end
  rescue JSON::ParserError => e
    @retry_state.record_failure(:normal)
    @config.logger.error { "[LDClient] JSON parsing failed for polling response - #{Util.retry_message(@retry_state.next_delay)}" }
    error_info = LaunchDarkly::Interfaces::DataSource::ErrorInfo.new(
      LaunchDarkly::Interfaces::DataSource::ErrorInfo::INVALID_DATA,
      0,
      e.to_s,
      Time.now
    )
    @config.data_source_update_sink&.update_status(LaunchDarkly::Interfaces::DataSource::Status::INTERRUPTED, error_info)
  rescue Impl::DataSource::UnexpectedResponseError => e
    kind = Util.classify_http_status(e.status)
    @retry_state.record_failure(kind)
    error_info = LaunchDarkly::Interfaces::DataSource::ErrorInfo.new(
      LaunchDarkly::Interfaces::DataSource::ErrorInfo::ERROR_RESPONSE, e.status, nil, Time.now)
    message = Util.http_error_retry_message(e.status, "polling request", @retry_state.next_delay)
    @config.logger.public_send(Util.failure_log_level(kind)) { "[LDClient] #{message}" }
    @config.data_source_update_sink&.update_status(LaunchDarkly::Interfaces::DataSource::Status::INTERRUPTED, error_info)
  rescue StandardError => e
    @retry_state.record_failure(:normal)
    Impl::Util.log_exception(@config.logger, "Exception while polling - #{Util.retry_message(@retry_state.next_delay)}", e)
    @config.data_source_update_sink&.update_status(
      LaunchDarkly::Interfaces::DataSource::Status::INTERRUPTED,
      LaunchDarkly::Interfaces::DataSource::ErrorInfo.new(LaunchDarkly::Interfaces::DataSource::ErrorInfo::UNKNOWN, 0, e.to_s, Time.now)
    )
  end
end

#start ⇒ Object

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.

Since:

  • 5.5.0



28
29
30
31
32
33
# File 'lib/ldclient-rb/impl/data_source/polling.rb', line 28

def start
  return @ready unless @started.make_true
  @config.logger.info { "[LDClient] Initializing polling connection" }
  @task.start
  @ready
end

#stop ⇒ Object

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.

Since:

  • 5.5.0



35
36
37
# File 'lib/ldclient-rb/impl/data_source/polling.rb', line 35

def stop
  stop_with_error_info
end