jruizgit / rules

Durable Rules Engine
MIT License
1.14k stars 209 forks source link

How to ensure event data is passed to the right context? #355

Open nikzasel opened 3 years ago

nikzasel commented 3 years ago

For example i have facts like this (they are stated only once per program run, around 40k facts): {id: 1, attribute_1_min: 32, attribute_1_max: 64, attribute_2: True} {id: 2, attribute_1_min: 64, attribute_1_max: 128, attribute_2: False} {id: 3, attribute_1_min: 128, attribute_1_max: 256, attribute_2: True}

Then i have events like this {id: 1, attribute_1_value: 48} {id: 2, attribute_1_value: 32} {id: 3, attribute_1_value: 512}

So attributes name presented in events and facts are different

I want to make rules something like: when_all m.id == s.id (event id must be equal to fact id) m.attribute_1_value > s.attribute_1_min (minimum value for fact with id) m.attribute_1_value < s.attribute_1_max (these two rules, to ensure, that event attribute value is in some range) s.attribute_2 == True (context attribute is true) So m must be info only from my events, and s must be data only from my facts.

My questions are: How to ensure that events data go in m, and facts data only go to the s variable? Are my rules correct? Because I get "Message not handled" exception when state_facts is used. But If I use rule like +s.id, then program just runs indefinitely.

Thank you.