Class: LaunchDarkly::Impl::EventSender Private
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::EventSender
- Defined in:
- lib/ldclient-rb/impl/event_sender.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.
Constant Summary collapse
- CURRENT_SCHEMA_VERSION =
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.
4- DEFAULT_RETRY_INTERVAL =
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.
1
Instance Method Summary collapse
-
#initialize(sdk_key, config, http_client = nil, retry_interval = DEFAULT_RETRY_INTERVAL) ⇒ EventSender
constructor
private
A new instance of EventSender.
- #send_event_data(event_data, description, is_diagnostic) ⇒ Object private
- #stop ⇒ Object private
Constructor Details
#initialize(sdk_key, config, http_client = nil, retry_interval = DEFAULT_RETRY_INTERVAL) ⇒ EventSender
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 EventSender.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ldclient-rb/impl/event_sender.rb', line 17 def initialize(sdk_key, config, http_client = nil, retry_interval = DEFAULT_RETRY_INTERVAL) @sdk_key = sdk_key @config = config @events_uri = config.events_uri + "/bulk" @diagnostic_uri = config.events_uri + "/diagnostic" @logger = config.logger @retry_interval = retry_interval @http_client_pool = UnboundedPool.new( lambda { Impl::Util.new_http_client(@config.events_uri, @config) }, lambda { |client| client.close }) end |
Instance Method Details
#send_event_data(event_data, description, is_diagnostic) ⇒ 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.
33 34 35 36 37 38 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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/ldclient-rb/impl/event_sender.rb', line 33 def send_event_data(event_data, description, is_diagnostic) uri = is_diagnostic ? @diagnostic_uri : @events_uri payload_id = is_diagnostic ? nil : SecureRandom.uuid begin http_client = @http_client_pool.acquire() response = nil 2.times do |attempt| if attempt > 0 @logger.warn { "[LDClient] Will retry posting events after #{@retry_interval} second" } sleep(@retry_interval) end begin @logger.debug { "[LDClient] sending #{description}: #{event_data}" } headers = {} headers["content-type"] = "application/json" headers["content-encoding"] = "gzip" if @config.compress_events Impl::Util.default_http_headers(@sdk_key, @config).each { |k, v| headers[k] = v } unless is_diagnostic headers["X-LaunchDarkly-Event-Schema"] = CURRENT_SCHEMA_VERSION.to_s headers["X-LaunchDarkly-Payload-ID"] = payload_id end body = event_data if @config.compress_events gzip = Zlib::GzipWriter.new(StringIO.new) gzip << event_data body = gzip.close.string end response = http_client.request("POST", uri, { headers: headers, body: body, }) rescue StandardError => exn @logger.warn { "[LDClient] Error sending events: #{exn.inspect}." } next end status = response.status.code # must fully read body for persistent connections body = response.to_s if status >= 200 && status < 300 res_time = nil unless response.headers["date"].nil? begin res_time = Time.httpdate(response.headers["date"]) rescue ArgumentError # Ignored end end return EventSenderResult.new(true, false, res_time) end must_shutdown = !Impl::Util.http_error_recoverable?(status) can_retry = !must_shutdown && attempt == 0 = Impl::Util.(status, "event delivery", can_retry ? "will retry" : "some events were dropped") @logger.error { "[LDClient] #{}" } if must_shutdown return EventSenderResult.new(false, true, nil) end end # used up our retries EventSenderResult.new(false, false, nil) ensure @http_client_pool.release(http_client) end 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.
29 30 31 |
# File 'lib/ldclient-rb/impl/event_sender.rb', line 29 def stop @http_client_pool.dispose_all() end |