Execute Multiple conditions at same time
Opened this issue · 1 comments
ailton-moreira commented
How can I execute multiple rules at same time?
I have two functions and I want to run it based on my conditions. It's possible to execute both condition at same time?
def order_more(items_to_order):
print("you ordered {} new items".format(items_to_order))
return items_to_order
def order_10X_more(items_to_order):
new_order = 10 * items_to_order
print("you ordered {} new items".format(new_order))
return new_order
rules = """
rule "order new items"
when
AND(products_in_stock < 20,
products_in_stock >= 5)
then
order_more(20)
end
rule "order new items urgent"
when
stock < 5,
then
order_10X_more(10)
end
"""
from business_rule_engine import RuleParser
params = {
'products_in_stock': 1,
'stock': 0
}
parser = RuleParser()
parser.register_function(order_more)
parser.register_function(order_10X_more)
parser.parsestr(rules)
parser.execute(params)
It's execute only the first function. But I want to run both functions, how can I do it?
Thank you!
dikshantrajput commented
Loop through rules and then execute them one by one like this:
parser.parsestr(rules) for rule in parser: try: rule.execute(params) if rule.status: //do whatever u want break except Exception as e: logging.error(e) print(e)