Rules Engine Execution
Business rule task helps evaluate business rules compiled in spreadsheets. Conductor currently supports the following formats:
- CSV
- XLS
- XLSX
Definitions
{
"name": "execute_rule",
"taskReferenceName": "execute_rule_ref",
"inputParameters": {
"ruleFileLocation": "https://business-rules.s3.amazonaws.com/rules.xlsx",
"executionStrategy": "FIRE_FIRST",
"inputColumns": {
"InputDate": "${workflow.input.inputDate}",
"ProductType": "${workflow.input.productType}"
},
"outputColumns": [
"Discount"
]
},
"type": "BUSINESS_RULE"
}
Input Parameters
Attribute | Description |
---|---|
ruleFileLocation | Specify the URL location of the rule file to be evaluated. The rule file can be available on the internet (Stored in AWS S3 or Azure Blob). Sample URL for each case;
|
executionStrategy | Specify the execution strategy to be followed. Currently, Conductor supports the following strategies:
|
inputColumns | Specifies the input to the rule file. It can be populated using previous task/workflow input/static input. |
outputColumns | Specifies the list of columns that will be present in the task output. The columns that are not present here are considered input columns whose values should be specified. |
Execution Strategy
To get an understanding of the execution Strategy, consider the below table:
Name | Price |
---|---|
Phone | 10$ |
Phone | 11$ |
Let’s assume the input Name is Phone. If the executionStrategy is FIRE_FIRST, then the output price will be $10. On the other hand, if the executionStrategy is FIRE_ALL, then the output price will be $11, as the second rule will overwrite the value of the price.
Supported Operators
Business rule task supports the following operators:
- Comparison operators for numeric value. <=,>=,=,<,>.
- String equals/not equals operator. productName != Phone.
- inList and !=inList operator. productName inList({"phone","laptop"}) will match if productName is phone or laptop.
- createList operator for output. createList({"A","B","C"}) will generate list {"A", "B", "C"} in output.
- Date comparison. Currently supported date formats are yyyy-MM-dd, yyyy-MMM-dd and yyyy-MM-dd HH:mm:ss.
Examples
- UI
- JSON Example
- Add task type
Business Rule
. - Configure the task with rules input file.
- Input and output columns.
{
"name": "execute_rule",
"taskReferenceName": "execute_rule_ref",
"inputParameters": {
"ruleFileLocation": "https://business-rules.s3.amazonaws.com/rules.xlsx",
"executionStrategy": "FIRE_FIRST",
"inputColumns": {
"InputDate": "${workflow.input.inputDate}",
"ProductType": "${workflow.input.productType}"
},
"outputColumns": [
"Discount"
]
},
"type": "BUSINESS_RULE"
}
Sample Workflow
Consider the below rule file for the input.
productType | productCategory | purchaseDate | itemCount | price | Discount | ShippingCharges
electronics | cellphone | <=2022-04-22 | 8 | != 100 | 11% | 5$
electronics | cellphone | <=2022-04-22 | 8 | < 100 | 13% | 15$
electronics | laptop | > 2022-mar-12 | >10 | <10.2 | 5% | 4$
beauty | powder | = 2022-01-01 | >15 | >=10.3 | 15% | 2$
food | pizza | < 2022-03-22 12:20:22 | 25 | >300 | 7% | 10$
And following workflow definition.
{
"name": "TestRule",
"tasks": [
{
"name": "rule",
"taskReferenceName": "rule",
"inputParameters": {
"ruleFileLocation": "Product.xlsx",
"executionStrategy": "FIRE_FIRST",
"ruleFileStorage": "LOCAL",
"inputColumns": {
"productType": "${workflow.input.productType}",
"productCategory": "${workflow.input.productCategory}",
"price": "${workflow.input.price}",
"itemCount": "${workflow.input.itemCount}",
"itemCode": "${workflow.input.itemCode}"
},
"outputColumns": [
"Discount",
"ShippingCharges"
]
},
"type": "BUSINESS_RULE"
}
]
}
If the workflow is triggered using input as:
{
"productType": "electronics",
"productCategory": "cellphone",
"price": "5",
"itemCount": "8",
"purchaseDate": "2022-04-22"
}
Then it will match the first row and generate output as:
{
"Discount" : "11%",
"ShippingCharges" : "5$"
}
Another Case
If the workflow is triggered using input as:
{
"productType": "electronics",
"productCategory": "laptop",
"price": "10.0",
"itemCount": "12",
"purchaseDate": "2022-04-22"
}
In order to compare double values, we should put the suffix .0. If it is not there, then it will match the third row and generate output as:
{
"Discount" : "5%",
"ShippingCharges" : "4$"
}
When we use FIRE_ALL as executionStrategy, with the workflow input as:
{
"productType": "electronics",
"productCategory": "cellphone",
"price": "5",
"itemCount": "8",
"purchaseDate": "2022-04-22"
}
Then it will match the second row since it also matches the criteria and generates output as:
{
"Discount" : "13%",
"ShippingCharges" : "5$"
}