|
7 | 7 |
|
8 | 8 |
|
9 | 9 | class EventRuleEngine:
|
10 |
| - def evaluate_pattern_on_event(self, event_pattern: dict, message_body: str | dict): |
11 |
| - if isinstance(message_body, str): |
| 10 | + def evaluate_pattern_on_event(self, compiled_event_pattern: dict, event: str | dict): |
| 11 | + if isinstance(event, str): |
12 | 12 | try:
|
13 |
| - body = json.loads(message_body) |
| 13 | + body = json.loads(event) |
14 | 14 | if not isinstance(body, dict):
|
15 | 15 | return False
|
16 | 16 | except json.JSONDecodeError:
|
17 | 17 | # Event pattern for the message body assume that the message payload is a well-formed JSON object.
|
18 | 18 | return False
|
19 | 19 | else:
|
20 |
| - body = message_body |
| 20 | + body = event |
21 | 21 |
|
22 |
| - return self._evaluate_nested_event_pattern_on_dict(event_pattern, payload=body) |
| 22 | + return self._evaluate_nested_event_pattern_on_dict(compiled_event_pattern, payload=body) |
23 | 23 |
|
24 | 24 | def _evaluate_nested_event_pattern_on_dict(self, event_pattern, payload: dict) -> bool:
|
25 | 25 | """
|
@@ -270,11 +270,11 @@ def _traverse(_object: dict, array=None, parent_key=None) -> list:
|
270 | 270 | return _traverse(nested_dict, array=[{}], parent_key=None)
|
271 | 271 |
|
272 | 272 |
|
273 |
| -class EventPatternValidator: |
| 273 | +class EventPatternCompiler: |
274 | 274 | def __init__(self):
|
275 | 275 | self.error_prefix = "Event pattern is not valid. Reason: "
|
276 | 276 |
|
277 |
| - def validate_event_pattern(self, event_pattern: str | dict) -> dict[str, t.Any]: |
| 277 | + def compile_event_pattern(self, event_pattern: str | dict) -> dict[str, t.Any]: |
278 | 278 | if isinstance(event_pattern, str):
|
279 | 279 | try:
|
280 | 280 | event_pattern = json.loads(event_pattern)
|
|
0 commit comments