@@ -151,20 +151,27 @@ def _do_fetch_with_retry(url, request_body, retry_config, timeout)
151
151
# The variation ID from the response.
152
152
153
153
backoff = retry_config . initial_backoff
154
- begin
155
- _do_fetch ( url , request_body , timeout )
156
- rescue StandardError => e
157
- if attempt < retry_config . max_retries
158
- backoff = [ backoff * ( retry_config . backoff_multiplier **( attempt + 1 ) ) , retry_config . max_backoff ] . min
159
- @logger . log ( Logger ::INFO , "Retrying CMAB request (attempt #{ attempt + 1 } ) after #{ backoff } seconds..." )
160
- Kernel . sleep ( backoff )
161
- attempt += 1
162
- retry
163
- else
164
- @logger . log ( Logger ::ERROR , "Max retries exceeded for CMAB request: #{ e . message } " )
165
- raise Optimizely ::CmabFetchError , "CMAB decision fetch failed (#{ e . message } )."
154
+
155
+ ( 0 ..retry_config . max_retries ) . each do |attempt |
156
+ begin
157
+ variation_id = _do_fetch ( url , request_body , timeout )
158
+ return variation_id
159
+ rescue StandardError => e
160
+ if attempt < retry_config . max_retries
161
+ @logger . log ( Logger ::INFO , "Retrying CMAB request (attempt #{ attempt + 1 } ) after #{ backoff } seconds..." )
162
+ Kernel . sleep ( backoff )
163
+
164
+ backoff = [
165
+ backoff * ( retry_config . backoff_multiplier **( attempt + 1 ) ) ,
166
+ retry_config . max_backoff
167
+ ] . min
168
+ else
169
+ @logger . log ( Logger ::ERROR , "Max retries exceeded for CMAB request: #{ e . message } " )
170
+ raise Optimizely ::CmabFetchError , "CMAB decision fetch failed (#{ e . message } )."
171
+ end
166
172
end
167
173
end
174
+
168
175
error_message = Optimizely ::Helpers ::Constants ::CMAB_FETCH_FAILED % 'Exhausted all retries for CMAB request.'
169
176
@logger . log ( Logger ::ERROR , error_message )
170
177
raise Optimizely ::CmabFetchError , error_message
0 commit comments