rules icon indicating copy to clipboard operation
rules copied to clipboard

Response from durable rules

Open a5rar opened this issue 6 years ago • 3 comments

Hi, I'm getting started with this using ruby, coming from a drools background. I'm relatively new to ruby and durable rules.

The kind of thing i'm struggling to figure out looking at the documents is how to return the goal achieved in the service response. The examples are only giving a print statement to console. I'm interested in composing an outcome and sending this as a response .

at the moment if i call http://localhost:4567/test/events with post body {"subject": "World"}

I get a response

{"outcome":0}

I want to return the full "hello world string as part of this service. And or in cases have a separate object which i start adding to when rules are running and then return this object at the end.

appreciate this is not an issue with the rule engine, but there is something lacking with documentation

a5rar avatar Jun 20 '18 12:06 a5rar

Hi, thanks for posting the question. Posting events and asserting facts is asynchronous. That is, in the example you have, when the http post completes, the event has been queued, but not necessarily processed. It is possible to save the outcome of the rule in the ruleset context and poll for it. The doc has a section describing this process:

https://github.com/jruizgit/rules/blob/master/docs/rb/reference.md#state

Hope this helps,

jruizgit avatar Jun 25 '18 04:06 jruizgit

Looks like this is the method you want to use to get the state: https://github.com/jruizgit/rules/blob/901749ec1905318025635da3bc289d968e487024/librb/durable.rb#L46-L48

Durable.get_state :rule_name, 'sid'

JerrodCarpenter avatar Oct 09 '19 20:10 JerrodCarpenter

polling is mentioned here... is there a way to poll the facts of a session at a given point in time? That is, after the facts have been asserted or posted, can the session be queried for the facts that exist (including facts derived from rules that triggered)? As mentioned here, print statements are the example, it would be nice to be able to return or insert general objects from a triggered rule and query for them.

Thanks for this package, it is very helpful.

mpettis avatar Feb 09 '20 01:02 mpettis