Skip to content

Unable to bind values in rule chaining. #679

Open
@arde0708

Description

@arde0708

My use case requires me to run three evaluations for each rule : RuleExpression, ValidationExpression, ActionExpression. I want to minimize C# code changes because these rules are dynamic and require frequent changes. I want to avoid C# code for executing the action because that would limit me to go through code deployment every time a rule is updated. And the order in which this is supposed to work is : If RuleExpression succeeds, we move to evaluate ValidationExpression and if ValidationExpression succeeds, we move to evaluate ActionExpression. With this context, here is a simplified example of what I did. Would appreciate some comments if this is not the right way

rules.json

[ { "WorkflowName": "Tuning", "Rules": [ { "RuleName": "EvaluationExpression", "SuccessEvent": "EvaluationExpressionPassed", "ErrorMessage": "EvaluationExpression not met.", "Expression": "metrics.current_value > 1000", "RuleExpressionType": "LambdaExpression" }, { "RuleName": "VerificationExpression", "SuccessEvent": "VerificationExpressionPassed", "ErrorMessage": "VerificationExpression failed.", "Expression": "@EvaluationExpression && metrics.cost_limit >= -1", "RuleExpressionType": "LambdaExpression" }, { "RuleName": "ActionExpression", "SuccessEvent": "ActionExpressionApplied", "ErrorMessage": "ActionExpression skipped.", "Expression": "VerificationExpressionPassed", "RuleExpressionType": "LambdaExpression", "Actions": { "OnSuccess": { "Name": "InlineAssignment", "Context": { "expression": "@VerificationExpression && metrics.cost_limit = metrics.cost_limit != -1 ? metrics.cost_limit + 100 : metrics.other_cost_limit + 100" } } }, "Enabled": true } ] } ]
The EvaluationExpression is getting evaluated as expected. However, this result is not getting passed to VerificationExpression. As a result, even though the metrics.cost_limit condition is met in VerificationExpression , I see VerificationExpression is getting evaluated to False. I tried removing @EvaluationExpression from the expression and then the VerificationExpression was evaluated as expected (True). I read other examples online and tried passing the SuccessEvent (EvaluationExpressionPassed) from the EvaluationExpression rule as well, but that did not work either.

My C# app code is below :

var workflows = JsonConvert.DeserializeObject<List>(ruleJson);
var metrics = MetricsProvider.GetSampleMetrics();
var inputs = new RuleParameter("metrics", metrics);
var engine = new RulesEngine.RulesEngine(workflows.ToArray(), new ReSettings { EnableScopedParams = true });
var results = await engine.ExecuteAllRulesAsync("Tuning", inputs);
foreach (var result in results)
{
Console.WriteLine($"- {result.Rule.RuleName}: {(result.IsSuccess ? "Passed" : "Failed")}");
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions