microsoft / RulesEngine

A Json based Rules Engine with extensive Dynamic expression support
https://microsoft.github.io/RulesEngine/
MIT License
3.47k stars 528 forks source link

New Operators: SequentialAnd and SequentialOr #565

Open douglasgalico opened 6 months ago

douglasgalico commented 6 months ago

In many complex scenarios, the order in which rules are evaluated significantly impacts the performance and outcome. Current operators like "And" and "Or" do not provide enough control for scenarios where the evaluation needs to be strictly sequential or stopped early based on certain conditions. "SequentialAnd" and "SequentialOr" are designed to address these limitations, offering more precise control and efficiency.

SequentialAnd:

Example:

{
  "RuleName": "Sample of SequentialAnd",
  "Rules": [
    { //Rule1 },
    { //Rule2 }, // If this rule fails we stop here with Success.
    { //Rule3 },
  ],
  "Operator": "SequentialAnd"
}

SequentialOr:

Example:

{
  "RuleName": "Sample of SequentialOr",
  "Rules": [
    { //Rule1 },
    { //Rule2 }, // If this rule succeed we stop here with Success.
    { //Rule3 },
  ],
  "Operator": "SequentialOr"
}

Implementation Considerations:

I invite the community and maintainers to discuss this proposal, the potential impacts, and any additional considerations or improvements. Any insight and feedback is more than appreciated.

Thank you for considering this enhancement. I look forward to your input and collaboration!

abbasc52 commented 6 months ago

@douglasgalico , your requirement appears very similar to performance mode settings in ReSettings.

https://github.com/microsoft/RulesEngine/blob/9bcf4f334b7b98b4ab2d347522ff86b3e884afed/src/RulesEngine/Models/ReSettings.cs#L80-L94

Can you check this and let me know if this is what you are looking for?

douglasgalico commented 5 months ago

@abbasc52 Thanks for the reply. I could say that's "almost" besides the fact the ReSettings will impact the whole workflow execution. The idea behind the new operators is to isolate this logic only for some set of rules in the same workflow (as we can do with And and Or).

What you think about it? I can help implementing it at RuleCompiler and their tests too :)

abbasc52 commented 5 months ago

@douglasgalico interesting idea would like to understand more on where you would need to selectively use it vs whole workflow execution.

I do understand one use case where for some workflow you may want performance mode vs for other normal mode. Currently we only support it at RulesEngine instance level, We can look at workflow level settings but for Rule level, it will help if you can share examples where it makes sense

douglasgalico commented 3 months ago

@abbasc52 I believe that's from use-case to use case, I currently use it extensively and having some complex workflows (with multiple rules and sub-rules) I've stepped many times in a situation where having a SequentialAnd/Or would be great for a specific block.

If we believe is something achievable and that will contribute to the product, then I can try to formalize a PR with the changes plus samples on it. What you think?

asulwer commented 5 days ago

i think your idea is great but...this project is no longer being maintained, please use my fork moving forward as it is being maintained