Skip to content

Commit

Permalink
Add ability to to set initial reconnect delay (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
keelerm84 authored Jan 28, 2022
1 parent 5dadfe0 commit 4a63c45
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions lib/ldclient-rb/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Config
# @option opts [Integer] :capacity (10000) See {#capacity}.
# @option opts [Float] :flush_interval (30) See {#flush_interval}.
# @option opts [Float] :read_timeout (10) See {#read_timeout}.
# @option opts [Float] :initial_reconnect_delay (1) See {#initial_reconnect_delay}.
# @option opts [Float] :connect_timeout (2) See {#connect_timeout}.
# @option opts [Object] :cache_store See {#cache_store}.
# @option opts [Object] :feature_store See {#feature_store}.
Expand Down Expand Up @@ -54,6 +55,7 @@ def initialize(opts = {})
@flush_interval = opts[:flush_interval] || Config.default_flush_interval
@connect_timeout = opts[:connect_timeout] || Config.default_connect_timeout
@read_timeout = opts[:read_timeout] || Config.default_read_timeout
@initial_reconnect_delay = opts[:initial_reconnect_delay] || Config.default_initial_reconnect_delay
@feature_store = opts[:feature_store] || Config.default_feature_store
@stream = opts.has_key?(:stream) ? opts[:stream] : Config.default_stream
@use_ldd = opts.has_key?(:use_ldd) ? opts[:use_ldd] : Config.default_use_ldd
Expand Down Expand Up @@ -180,6 +182,13 @@ def offline?
#
attr_reader :read_timeout

#
# The initial delay before reconnecting after an error in the SSE client.
# This only applies to the streaming connection.
# @return [Float]
#
attr_reader :initial_reconnect_delay

#
# The connect timeout for network connections in seconds.
# @return [Float]
Expand Down Expand Up @@ -395,6 +404,14 @@ def self.default_read_timeout
10
end

#
# The default value for {#initial_reconnect_delay}.
# @return [Float] 1
#
def self.default_initial_reconnect_delay
1
end

#
# The default value for {#connect_timeout}.
# @return [Float] 10
Expand Down
3 changes: 2 additions & 1 deletion lib/ldclient-rb/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def start
headers: headers,
read_timeout: READ_TIMEOUT_SECONDS,
logger: @config.logger,
socket_factory: @config.socket_factory
socket_factory: @config.socket_factory,
reconnect_time: @config.initial_reconnect_delay
}
log_connection_started
@es = SSE::Client.new(@config.stream_uri + "/all", **opts) do |conn|
Expand Down

0 comments on commit 4a63c45

Please sign in to comment.