Closed jlugao closed 4 years ago
After a meeting, this is the proposed api:
class Engine():
def __init__():
self.conditions = []
self.actions = []
def export_engine_metadata():
return {
"conditions": [condition.export_condition() for condition in conditions],
"actions": [condition.export_action() for action in actions],
}
def run(rule, session):
parsed_rules = parse_rules(rule)
for idx, item in enumerate(parsed_rules):
item.run(session)
session["runtime"] = {
"call_stack" : session.get("runtime", []).append({
"index": idx,
"item": item
}),
}
...
class Item(ABC):
def get_item_metadata():
...
def export_item():
...
class Condition(Item):
...
class Action(Item):
...
class Operator(Item):
...
Payload:
{
"name": "first_condition",
"args": {"lower_number": 3, "greater_number": 10},
"type": "condition"
},
{
"name": "print_the_equation",
"args": {"lower_number": 3, "greater_number": 10},
"type": "action"
}
Well, this was part of the first major refactoring. So far so good
This project started to solve a very specific pain of mine, however many use cases are interesting and could be explored. Basically what was going on in my mind was: I want this lib (that is not maintained since 2016) with FastApi-like interface. A couple of options for rule engine were available and didn't match my criteria, such as:
Some of the other use cases I could come up with: