-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using the output of an action in a generated fact #85
Comments
What I'm presently doing is running everything through the engine with just facts, and then have a synchronization process afterwards that queries the engine and generates new database records for anything that it detects that's missing. But that's a clunky process and it limits the complexity of rule sets. |
Hard to say without seeing the code. The biggest problem is that a production node may activate and deactivate several times before the engine reaches a stable state, depending on the ruleset, so changing persistent state from action blocks could have unintended effects. If you don't have negative matchers that may become invalidated, that might not be an issue for you. But that aside, action blocks aren't really designed to have their output affect the engine state. I'd continue your approach of running the engine on facts only and committing the state after it settles. Again, I can't really comment on the problems you're having with it without seeing the code; but have a look at the new entity iterator API in v0.4, I wrote it specifically to alleviate some of the pain of walking the knowledge base. It's still a bit verbose but I found it to be reasonably readable in practice. Remember that you don't need external identity like database IDs to work with facts; you could generate placeholder objects ( |
Hi @ulfurinn, probably I have the same situation and i will try to explain it in a code:
it all works, and it will print the results as expected. I can do it for all operations, which is nice. However I wanted to go a step further, and instead of puts, I wanted to generate a new fact and match it in another rules, so i added the following code:
That when I run it, I get the follow results:
which means, the second rule "results" is being triggered, but the multiplication results isn't being carried on.. there is a way to accomplish what I'm trying to, or am I misusing the rules engine? My expectation was, to get a fact like Thanks! |
The direct content of The |
The docs say, about action blocks in productions, "Avoid modifying the engine inside action blocks (i.e., asserting and retracting facts and installing new rules). There are safer ways of doing this. Action blocks should only be used for side effects."
When a production fires, I want to write a record to a database, and then use the generated primary key of that record to assert a new fact for downstream processing. What is the best way to do that? Does the warning about modifying the engine apply to action objects as well? What is the safer way of doing this?
The text was updated successfully, but these errors were encountered: