Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Operators: SequentialAnd and SequentialOr #565

Open
douglasgalico opened this issue Dec 22, 2023 · 4 comments
Open

New Operators: SequentialAnd and SequentialOr #565

douglasgalico opened this issue Dec 22, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@douglasgalico
Copy link

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:

  • Each rule is evaluated in order. The evaluation proceeds to the next rule only if the current rule is true.
  • If any rule evaluates to false, the entire set immediately fails, and no further rules are evaluated.
  • This is similar to the "And" operator but with the added functionality that the order is strictly followed, and evaluation stops after the first false condition.

Example:

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

SequentialOr:

  • Each rule is evaluated in order. The evaluation proceeds to the next rule only if the current rule is false.
  • If any rule evaluates to true, the entire set immediately succeeds, and no further rules are evaluated.
  • If all rules are evaluated to false, the entire set immediately fails.
  • This is similar to the "Or" operator but with the added functionality that the order is strictly followed, and evaluation stops after the first true condition.

Example:

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

Implementation Considerations:

  • Ensure compatibility with existing rule engine structures and evaluate the impact on performance.
  • Provide clear documentation and examples for proper usage and understanding.
  • Include comprehensive testing scenarios to ensure reliability and expected behavior.

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
Copy link
Contributor

abbasc52 commented Jan 3, 2024

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

public NestedRuleExecutionMode NestedRuleExecutionMode { get; set; } = NestedRuleExecutionMode.All;
public MemCacheConfig CacheConfig { get; set; }
}
public enum NestedRuleExecutionMode
{
/// <summary>
/// Executes all nested rules
/// </summary>
All,
/// <summary>
/// Skips nested rules whose execution does not impact parent rule's result
/// </summary>
Performance
}

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

@douglasgalico
Copy link
Author

@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
Copy link
Contributor

@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

@abbasc52 abbasc52 added the enhancement New feature or request label Jan 12, 2024
@douglasgalico
Copy link
Author

douglasgalico commented Mar 8, 2024

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants