project-flogo/rules

Get data back or modify data in an Action

eddie-velez opened this issue · 4 comments

Current behavior:
When a condition evaluates to true the assigned action func is triggered and does something with the map of tuples but the function signature does not allow for data to be returned or the tuple to be modified in any way.

Expected behavior:
If data is passed into the rules engine could we get data that is modified back to the caller

What is the motivation / use case for changing the behavior?
Ex. Given two services: service1 and EngineService:

  • service1 passes data to EngineService for processing.
  • EngineService has a rule: "if x == 5; then set y = 10;"
  • how can we get 'y' back to service1 from the action

Additional information you deem important (e.g. I need this tomorrow):

You can set service1 via the rule context, which is available in the action, and pass 'y' back to service1 that way.

@balamg would you have an example of that, assuming that the two services are interacting via REST or gRPC?

I was assuming the two services to be part of the same application but looks like that not true. So then, it would depend on your setup. Is your rules service a Flogo app (with a REST trigger) or are you custom building your your rules service, where you have control over the rules service API?
If it's the former, there is no way to synchronously get back the result as part of the rest call that asserts the event. In this case, the calling service must expose an endpoint to collect the results, that can be invoked from the action callback. But that would be asynchronous. On the other hand if its a custom application and you have control over the rules API, you could set your HTTP request context object in the context.Context and extract it back in the action callback to response back to your request. Hope this helps!

Yep! this works, ty