@@ -162,36 +162,26 @@ def get_condition_result(self) -> DataConditionResult:
162
162
163
163
return None
164
164
165
- def evaluate_value (self , value : T ) -> DataConditionResult :
165
+ def _evaluate_operator (self , condition_type : Condition , value : T ) -> DataConditionResult :
166
+ # If the condition is a base type, handle it directly
167
+ op = CONDITION_OPS [condition_type ]
168
+ result = None
166
169
try :
167
- condition_type = Condition ( self .type )
168
- except ValueError :
170
+ result = op ( cast ( Any , value ), self .comparison )
171
+ except TypeError :
169
172
logger .exception (
170
- "Invalid condition type" ,
171
- extra = {"type" : self .type , "id" : self .id },
173
+ "Invalid comparison for data condition" ,
174
+ extra = {
175
+ "comparison" : self .comparison ,
176
+ "value" : value ,
177
+ "type" : self .type ,
178
+ "condition_id" : self .id ,
179
+ },
172
180
)
173
- return None
174
-
175
- if condition_type in CONDITION_OPS :
176
- # If the condition is a base type, handle it directly
177
- op = CONDITION_OPS [Condition (self .type )]
178
- result = None
179
- try :
180
- result = op (cast (Any , value ), self .comparison )
181
- except TypeError :
182
- logger .exception (
183
- "Invalid comparison for data condition" ,
184
- extra = {
185
- "comparison" : self .comparison ,
186
- "value" : value ,
187
- "type" : self .type ,
188
- "condition_id" : self .id ,
189
- },
190
- )
191
181
192
- return self . get_condition_result () if result else None
182
+ return result
193
183
194
- # Otherwise, we need to get the handler and evaluate the value
184
+ def _evaluate_condition ( self , condition_type : Condition , value : T ) -> DataConditionResult :
195
185
try :
196
186
handler = condition_handler_registry .get (condition_type )
197
187
except registry .NoRegistrationExistsError :
@@ -237,7 +227,28 @@ def evaluate_value(self, value: T) -> DataConditionResult:
237
227
},
238
228
)
239
229
230
+ return result
231
+
232
+ def evaluate_value (self , value : T ) -> DataConditionResult :
233
+ try :
234
+ condition_type = Condition (self .type )
235
+ except ValueError :
236
+ logger .exception (
237
+ "Invalid condition type" ,
238
+ extra = {"type" : self .type , "id" : self .id },
239
+ )
240
+ return None
241
+
242
+ result : DataConditionResult
243
+ if condition_type in CONDITION_OPS :
244
+ result = self ._evaluate_operator (condition_type , value )
245
+ else :
246
+ result = self ._evaluate_condition (condition_type , value )
247
+
248
+ metrics .incr ("workflow_engine.data_condition.evaluation" , tags = {"type" : self .type })
249
+
240
250
if isinstance (result , bool ):
251
+ # If the result is True, get the result from `.condition_result`
241
252
return self .get_condition_result () if result else None
242
253
243
254
return result
0 commit comments