Skip to content

Commit 0dc594e

Browse files
authored
Merge pull request #78 from launchdarkly/dr/2.0.4
Update to sse client with heartbeat detection + exponential backoff
2 parents 23bb9ae + e9bd4ec commit 0dc594e

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

ldclient-rb.gemspec

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ Gem::Specification.new do |spec|
2929
spec.add_runtime_dependency "faraday-http-cache", "~> 1.3.0"
3030
spec.add_runtime_dependency "thread_safe", "~> 0.3"
3131
spec.add_runtime_dependency "net-http-persistent", "~> 2.9"
32-
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0.0"
32+
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0.4"
3333
spec.add_runtime_dependency "hashdiff", "~> 0.2"
34-
spec.add_runtime_dependency "ld-celluloid-eventsource", "~> 0.5"
34+
spec.add_runtime_dependency "ld-celluloid-eventsource", "~> 0.8.1"
35+
spec.add_runtime_dependency "nio4r", "~> 1.1" # for maximum ruby version compatibility.
36+
3537
spec.add_runtime_dependency "waitutil", "0.2"
3638
end

lib/ldclient-rb/config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Config
3737
# @option opts [Boolean] :offline (false) Whether the client should be initialized in
3838
# offline mode. In offline mode, default values are returned for all flags and no
3939
# remote network requests are made.
40-
# @option opts [Float] :poll_interval (30) The number of seconds between polls for flag updates
40+
# @option opts [Float] :poll_interval (1) The number of seconds between polls for flag updates
4141
# if streaming is off.
4242
# @option opts [Boolean] :stream (true) Whether or not the streaming API should be used to receive flag updates.
4343
#

lib/ldclient-rb/requestor.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ def request_flag(key)
2424
end
2525

2626
def make_request(path)
27-
res = @client.get (@config.base_uri + path) do |req|
27+
uri = @config.base_uri + path
28+
res = @client.get (uri) do |req|
2829
req.headers["Authorization"] = @sdk_key
2930
req.headers["User-Agent"] = "RubyClient/" + LaunchDarkly::VERSION
3031
req.options.timeout = @config.read_timeout
3132
req.options.open_timeout = @config.connect_timeout
3233
end
3334

35+
@config.logger.debug("[LDClient] Got response from uri: #{uri}\n\tstatus code: #{res.status}\n\theaders: #{res.headers}\n\tbody: #{res.body}")
36+
3437
if res.status == 401
3538
@config.logger.error("[LDClient] Invalid SDK key")
3639
return nil

lib/ldclient-rb/stream.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "concurrent/atomics"
22
require "json"
3-
require "celluloid/eventsource"
3+
require "ld_celluloid_eventsource/eventsource"
44

55
module LaunchDarkly
66
PUT = :put
@@ -40,14 +40,11 @@ def start
4040
conn.on(DELETE) { |message| process_message(message, DELETE) }
4141
conn.on(INDIRECT_PUT) { |message| process_message(message, INDIRECT_PUT) }
4242
conn.on(INDIRECT_PATCH) { |message| process_message(message, INDIRECT_PATCH) }
43-
conn.on_error do |message|
44-
@config.logger.error("[LDClient] Error connecting to stream. Status code: #{message[:status_code]}")
45-
end
4643
end
4744
end
4845

4946
def process_message(message, method)
50-
@config.logger.debug("[LDClient] Stream received #{method} message")
47+
@config.logger.debug("[LDClient] Stream received #{method} message: #{message.data}")
5148
if method == PUT
5249
message = JSON.parse(message.data, symbolize_names: true)
5350
@store.init(message)

0 commit comments

Comments
 (0)