@@ -6,8 +6,8 @@ class Synchronizer
66 include SplitIoClient ::Cache ::Fetchers
77 include SplitIoClient ::Cache ::Senders
88
9- ON_DEMAND_FETCH_BACKOFF_BASE_MS = 10_000
10- ON_DEMAND_FETCH_BACKOFF_MAX_WAIT_MS = 60_000
9+ ON_DEMAND_FETCH_BACKOFF_BASE_SECONDS = 10
10+ ON_DEMAND_FETCH_BACKOFF_MAX_WAIT_SECONDS = 60
1111 ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES = 10
1212
1313 def initialize (
@@ -29,7 +29,6 @@ def initialize(
2929 @impressions_api = SplitIoClient ::Api ::Impressions . new ( @api_key , @config , params [ :telemetry_runtime_producer ] )
3030 @impression_counter = params [ :imp_counter ]
3131 @telemetry_synchronizer = params [ :telemetry_synchronizer ]
32- @backoff = new SSE ::EventSource ::BackOff . new ( )
3332 end
3433
3534 def sync_all
@@ -58,14 +57,15 @@ def stop_periodic_fetch
5857 end
5958
6059 def fetch_splits ( target_change_number )
61- return if target_change_number <= @splits_repository . get_change_number
60+ return if target_change_number <= @splits_repository . get_change_number . to_i
6261
6362 fetch_options = { cache_control_headers : true , till : nil }
6463
6564 result = attempt_splits_sync ( target_change_number ,
6665 fetch_options ,
6766 @config . on_demand_fetch_max_retries ,
68- @config . on_demand_fetch_retry_delay_ms )
67+ @config . on_demand_fetch_retry_delay_seconds ,
68+ false )
6969
7070 attempts = @config . on_demand_fetch_max_retries - result [ :remaining_attempts ]
7171 if result [ :success ]
@@ -79,7 +79,8 @@ def fetch_splits(target_change_number)
7979 result = attempt_splits_sync ( target_change_number ,
8080 fetch_options ,
8181 ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES ,
82- @config . on_demand_fetch_retry_delay_ms )
82+ nil ,
83+ true )
8384
8485 attempts = @config . on_demand_fetch_max_retries - result [ :remaining_attempts ]
8586
@@ -100,8 +101,9 @@ def fetch_segment(name)
100101
101102 private
102103
103- def attempt_splits_sync ( target_cn , fetch_options , max_retries , retry_delay_ms )
104+ def attempt_splits_sync ( target_cn , fetch_options , max_retries , retry_delay_seconds , with_backoff )
104105 remaining_attempts = max_retries
106+ backoff = SSE ::EventSource ::BackOff . new ( ON_DEMAND_FETCH_BACKOFF_BASE_SECONDS , 0 , ON_DEMAND_FETCH_BACKOFF_MAX_WAIT_SECONDS ) if with_backoff
105107
106108 loop do
107109 remaining_attempts -= 1
@@ -111,7 +113,8 @@ def attempt_splits_sync(target_cn, fetch_options, max_retries, retry_delay_ms)
111113 return split_sync_result ( true , remaining_attempts , segment_names ) if target_cn <= @splits_repository . get_change_number
112114 return split_sync_result ( false , remaining_attempts , segment_names ) if remaining_attempts <= 0
113115
114- sleep ( retry_delay_ms )
116+ delay = with_backoff ? backoff . interval : retry_delay_seconds
117+ sleep ( delay )
115118 end
116119 end
117120
0 commit comments