@@ -46,8 +46,7 @@ def __init__(self, optimizely_client, user_id, user_attributes=None):
46
46
47
47
self ._user_attributes = user_attributes .copy () if user_attributes else {}
48
48
self .lock = threading .Lock ()
49
- with self .lock :
50
- self .forced_decisions = {}
49
+ self .forced_decisions = {}
51
50
self .log = logger .SimpleLogger (min_level = enums .LogLevels .INFO )
52
51
53
52
# decision context
@@ -149,70 +148,61 @@ def as_json(self):
149
148
'attributes' : self .get_user_attributes (),
150
149
}
151
150
152
- def set_forced_decision (self , OptimizelyDecisionContext , OptimizelyForcedDecision ):
151
+ def set_forced_decision (self , decision_context , decision ):
153
152
"""
154
153
Sets the forced decision for a given decision context.
155
154
156
155
Args:
157
- OptimizelyDecisionContext : a decision context.
158
- OptimizelyForcedDecision : a forced decision.
156
+ decision_context : a decision context.
157
+ decision : a forced decision.
159
158
160
159
Returns:
161
160
True if the forced decision has been set successfully.
162
161
"""
163
- config = self .client .get_optimizely_config ()
164
-
165
- if self .client is None or config is None :
162
+ if not self .client .config_manager .get_config ():
166
163
self .log .logger .error (OptimizelyDecisionMessage .SDK_NOT_READY )
167
164
return False
168
165
169
- context = OptimizelyDecisionContext
170
- decision = OptimizelyForcedDecision
171
-
172
166
with self .lock :
173
- self .forced_decisions [context ] = decision
167
+ self .forced_decisions [decision_context ] = decision
174
168
175
169
return True
176
170
177
- def get_forced_decision (self , OptimizelyDecisionContext ):
171
+ def get_forced_decision (self , decision_context ):
178
172
"""
179
173
Gets the forced decision (variation key) for a given decision context.
180
174
181
175
Args:
182
- OptimizelyDecisionContext : a decision context.
176
+ decision_context : a decision context.
183
177
184
178
Returns:
185
179
A variation key or None if forced decisions are not set for the parameters.
186
180
"""
187
- config = self .client .get_optimizely_config ()
188
-
189
- if self .client is None or config is None :
181
+ if not self .client .config_manager .get_config ():
190
182
self .log .logger .error (OptimizelyDecisionMessage .SDK_NOT_READY )
191
183
return None
192
184
193
- forced_decision_key = self .find_forced_decision (OptimizelyDecisionContext )
185
+ forced_decision_key = self .find_forced_decision (decision_context )
194
186
195
187
return forced_decision_key if forced_decision_key else None
196
188
197
- def remove_forced_decision (self , OptimizelyDecisionContext ):
189
+ def remove_forced_decision (self , decision_context ):
198
190
"""
199
191
Removes the forced decision for a given flag and an optional rule.
200
192
201
193
Args:
202
- OptimizelyDecisionContext : a decision context.
194
+ decision_context : a decision context.
203
195
204
196
Returns:
205
197
Returns: true if the forced decision has been removed successfully.
206
198
"""
207
- config = self .client .get_optimizely_config ()
208
-
209
- if self .client is None or config is None :
199
+ if not self .client .config_manager .get_config ():
210
200
self .log .logger .error (OptimizelyDecisionMessage .SDK_NOT_READY )
211
201
return False
212
202
213
203
with self .lock :
214
- if OptimizelyDecisionContext in self .forced_decisions .keys ():
215
- del self .forced_decisions [OptimizelyDecisionContext ]
204
+ if decision_context in self .forced_decisions .keys ():
205
+ del self .forced_decisions [decision_context ]
216
206
return True
217
207
218
208
return False
@@ -224,9 +214,7 @@ def remove_all_forced_decisions(self):
224
214
Returns:
225
215
True if forced decisions have been removed successfully.
226
216
"""
227
- config = self .client .get_optimizely_config ()
228
-
229
- if self .client is None or config is None :
217
+ if not self .client .config_manager .get_config ():
230
218
self .log .logger .error (OptimizelyDecisionMessage .SDK_NOT_READY )
231
219
return False
232
220
@@ -235,23 +223,23 @@ def remove_all_forced_decisions(self):
235
223
236
224
return True
237
225
238
- def find_forced_decision (self , OptimizelyDecisionContext ):
226
+ def find_forced_decision (self , decision_context ):
239
227
240
228
with self .lock :
241
229
if not self .forced_decisions :
242
230
return None
243
231
244
232
# must allow None to be returned for the Flags only case
245
- return self .forced_decisions .get (OptimizelyDecisionContext )
233
+ return self .forced_decisions .get (decision_context )
246
234
247
- def find_validated_forced_decision (self , OptimizelyDecisionContext , options ):
235
+ def find_validated_forced_decision (self , decision_context , options ):
248
236
249
237
reasons = []
250
238
251
- forced_decision_response = self .find_forced_decision (OptimizelyDecisionContext )
239
+ forced_decision_response = self .find_forced_decision (decision_context )
252
240
253
- flag_key = OptimizelyDecisionContext .flag_key
254
- rule_key = OptimizelyDecisionContext .rule_key
241
+ flag_key = decision_context .flag_key
242
+ rule_key = decision_context .rule_key
255
243
256
244
if forced_decision_response :
257
245
variation = self .client .get_flag_variation_by_key (flag_key , forced_decision_response .variation_key )
0 commit comments