Skip to main content

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

AttributeDescription
ruleFileLocationSpecify 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;
  • On the web: https://example.com/rules.csv
  • AWS S3 - https://business-rules.s3.amazonaws.com/rules.xlsx
  • Azure blob - https://business-rules.blob.core.windows.net/rules/Date.xlsx
executionStrategySpecify the execution strategy to be followed. Currently, Conductor supports the following strategies:
  • FIRE_FIRST - The first rule which gets matched will be used to generate the output.
  • FIRE_ALL - All the rule that matches will be used to generate the output.
inputColumnsSpecifies the input to the rule file. It can be populated using previous task/workflow input/static input.
outputColumnsSpecifies 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.
cacheConfigEnabling this option allows saving the cache output of the task. On enabling you can provide the following parameters:
  • TTL (in seconds) - Provide the time to live in seconds.You can also pass this parameter as variables.
  • Cache Key - Provide the cache key, which is a string with parameter substitution based on the task input. You can also pass this parameter as variables.

Execution Strategy

To get an understanding of the execution Strategy, consider the below table:

NamePrice
Phone10$
Phone11$

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:

  1. Comparison operators for numeric value. <=,>=,=,<,>.
  2. String equals/not equals operator. productName != Phone.
  3. inList and !=inList operator. productName inList({"phone","laptop"}) will match if productName is phone or laptop.
  4. createList operator for output. createList({"A","B","C"}) will generate list {"A", "B", "C"} in output.
  5. Date comparison. Currently supported date formats are yyyy-MM-dd, yyyy-MMM-dd and yyyy-MM-dd HH:mm:ss.

Examples



  1. Add task type Business Rule.
  2. Configure the task with rules input file.
  3. Input and output columns.

Adding 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$"
}