The rule engine you always deserved.
RulePipe is a declarative, scalable, highly configurable rule engine. Usage areas include, but not limited to;
- Classification
- Filtering
- Triggering other tasks
- User-driven flow implementations
- Event based checks
- Domain specific complex rule inputs
RulePipe uses some Python package as a module. These packages must be installed during installation.
- Clone this repository
git clone https://github.com/emregeldegul/rulepipe.git - Change directory to repository directory
cd rulepipe - Install the necessary packages
$ pip install -r requirements.txt - Rename the .env.example file to .env
mv .env.example .env - Change the database settings in the .env file.
- Run flask service
export FLASK_APP=api.py && python3 -m flask run
Is enough for installing and using RulePile as a RESTful service.
If you have successfully installed and runned RulePipe, now you can use it as a rule engine service.
To add a simple rule to your engine:
curl --header "Content-Type: application/json" --request POST --data '
{
"type": "rule",
"match": "all",
"rules": [
{
"field": "responseTimeInSeconds",
"condition": "lte",
"value": 3.45
},
{
"field": "statusCode",
"condition": "gte",
"value": 200
}
]
}
' http://localhost:5000/add_rule/myNewRuleIn this rule screnario, if "responseTimeInSeconds" value is less than or
equal to 3.45 and "statusCode" value is greater than or equal to 200 ,
input statement going to return True else return False.
(because "Match" is "all", it returns True if all the conditions are True)
When you run make this request, if everything is OK, result is "OK".
To check a simple statement:
curl --header "Content-Type: application/json" --request POST --data '
{
"responseTimeInSeconds": 2,
"statusCode": 200
}
' http://localhost:5000/execute_rule/myNewRuleThis statement is provides the conditions of our rule, so its result should be:
{"response":true} with 200 return code.
If we check another statement as below:
curl --header "Content-Type: application/json" --request POST --data '
{
"responseTimeInSeconds": 5,
"statusCode": 404
}
' http://localhost:5000/execute_rule/myNewRuleAlthough 404 is greather than 200, because of 5 is greater than 3.45
our condition is not providing the condition of our rule. So its result should
be as:
{"response":false} with 200 return code.
In Progress:
To Do:
- Support defining custom conditions
- Support predefined actions
- Support defining custom actions
- Support for OpenTracing
- Dockerize and prepare Docker Compose file
Completed:
- Add REST API
- Add persistent DB (maybe MongoDB)
- Add cache for rules (maybe Redis)
- Add cache for statement return values
- Add webhooks for Telegram to track progress
- Add logging and use log levels
- Read database information from config file and environment variables
- Support subfields in JSON (probably needs dot notation)
- Support nested rules
- Make caching optional
- Set hash of data as Redis keys
- Enable precedence in environment variables
