Rule Composability / Condition based Facts #336
Closed
chris-pardy
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Imagine a hypothetical scenario in which we're using our rules editor to automate a time off system.
We have time off requests which can either be automatically approved, automatically rejected, or left for manager approval.
For our hypothetical scenario we want to reject any time off requests which exceed the employees accrued time off by 16 hours.
We want to automatically approve any requests that won't be rejected where the first day off is more than 3 weeks away.
As it stands today we'd have to do something like this:
The problem is that if our rejection conditions change then we'd need to edit our approval conditions to reflect that, this becomes a maintenance problem as we scale out.
A solution is to extract the common checks into a fact, that produces the following result:
This allows us to keep the logic for auto rejecting in one place, and leverage it in both places. However it has also moved the configuration of the auto rejection logic out of the easily transportable json and into code.
My proposal would be to allow the addition of facts that follow the same structure of the rules. For the above fact we'd do this.
We could add this to the engine via the
engine.addFact
method the same way that rules are currently added.Facts created with conditions like this would return a boolean value based on if the conditions are true or false.
Why Do this instead of XXX
Adding facts in this way for extension and composition in several ways:
any
block.Additionally you can just use the mechanism to allow the creation of facts that encapsulate a complex and re-used condition and allow those edits to be done by someone editing the JSON files, and not needing to write code.
This solves for the use case covered by #263
Beta Was this translation helpful? Give feedback.
All reactions