@@ -21,7 +21,6 @@ import (
21
21
"encoding/json"
22
22
"fmt"
23
23
"strconv"
24
- "time"
25
24
26
25
"github.com/google/uuid"
27
26
"github.com/optimizely/go-sdk/v2/pkg/cache"
@@ -76,7 +75,7 @@ func (s *DefaultCmabService) GetDecision(
76
75
// Check if we should ignore the cache
77
76
if options != nil && hasOption (options , decide .IgnoreCMABCache ) {
78
77
reasons = append (reasons , "Ignoring CMAB cache as requested" )
79
- decision , err := s .fetchDecisionWithRetry (ruleID , userContext .ID , filteredAttributes )
78
+ decision , err := s .fetchDecision (ruleID , userContext .ID , filteredAttributes )
80
79
if err != nil {
81
80
return Decision {Reasons : reasons }, err
82
81
}
@@ -136,7 +135,7 @@ func (s *DefaultCmabService) GetDecision(
136
135
}
137
136
138
137
// Fetch new decision
139
- decision , err := s .fetchDecisionWithRetry (ruleID , userContext .ID , filteredAttributes )
138
+ decision , err := s .fetchDecision (ruleID , userContext .ID , filteredAttributes )
140
139
if err != nil {
141
140
decision .Reasons = append (reasons , decision .Reasons ... )
142
141
return decision , fmt .Errorf ("CMAB API error: %w" , err )
@@ -156,51 +155,29 @@ func (s *DefaultCmabService) GetDecision(
156
155
return decision , nil
157
156
}
158
157
159
- // fetchDecisionWithRetry fetches a decision from the CMAB API with retry logic
160
- func (s * DefaultCmabService ) fetchDecisionWithRetry (
158
+ // fetchDecision fetches a decision from the CMAB API
159
+ func (s * DefaultCmabService ) fetchDecision (
161
160
ruleID string ,
162
161
userID string ,
163
162
attributes map [string ]interface {},
164
163
) (Decision , error ) {
165
164
cmabUUID := uuid .New ().String ()
166
165
reasons := []string {}
167
166
168
- // Retry configuration
169
- maxRetries := 3
170
- backoffFactor := 2
171
- initialBackoff := 100 * time .Millisecond
167
+ s .logger .Debug (fmt .Sprintf ("Fetching CMAB decision for rule %s and user %s" , ruleID , userID ))
172
168
173
- var lastErr error
174
-
175
- for attempt := 0 ; attempt < maxRetries ; attempt ++ {
176
- // Exponential backoff if this is a retry
177
- if attempt > 0 {
178
- backoffDuration := initialBackoff * time .Duration (backoffFactor ^ attempt )
179
- time .Sleep (backoffDuration )
180
- reasons = append (reasons , fmt .Sprintf ("Retry attempt %d/%d after backoff" , attempt + 1 , maxRetries ))
181
- }
182
-
183
- s .logger .Debug (fmt .Sprintf ("Fetching CMAB decision for rule %s and user %s (attempt %d/%d)" ,
184
- ruleID , userID , attempt + 1 , maxRetries ))
185
-
186
- variationID , err := s .cmabClient .FetchDecision (ruleID , userID , attributes , cmabUUID )
187
- if err == nil {
188
- reasons = append (reasons , fmt .Sprintf ("Successfully fetched CMAB decision on attempt %d/%d" , attempt + 1 , maxRetries ))
189
- return Decision {
190
- VariationID : variationID ,
191
- CmabUUID : cmabUUID ,
192
- Reasons : reasons ,
193
- }, nil
194
- }
195
-
196
- lastErr = err
197
- s .logger .Warning (fmt .Sprintf ("CMAB API request failed (attempt %d/%d): %v" ,
198
- attempt + 1 , maxRetries , err ))
169
+ variationID , err := s .cmabClient .FetchDecision (ruleID , userID , attributes , cmabUUID )
170
+ if err != nil {
171
+ reasons = append (reasons , "Failed to fetch CMAB decision" )
172
+ return Decision {Reasons : reasons }, fmt .Errorf ("CMAB API error: %w" , err )
199
173
}
200
174
201
- reasons = append (reasons , fmt .Sprintf ("Failed to fetch CMAB decision after %d attempts" , maxRetries ))
202
- return Decision {Reasons : reasons }, fmt .Errorf ("failed to fetch CMAB decision after %d attempts: %w" ,
203
- maxRetries , lastErr )
175
+ reasons = append (reasons , "Successfully fetched CMAB decision" )
176
+ return Decision {
177
+ VariationID : variationID ,
178
+ CmabUUID : cmabUUID ,
179
+ Reasons : reasons ,
180
+ }, nil
204
181
}
205
182
206
183
// filterAttributes filters user attributes based on CMAB configuration
0 commit comments