Hi Rich / @rlkoshak and everybody else,
I plan to “modularize” my rules by creating reusable functions. I have seen and read Creating Your Own Library in the documentation, however, I like to know what you think about this approach:
- Storing the function as usual as a script
- The main script calls the “function script” by
rules.runRule(uid, {'parameter1': 'value'});
- and gets the return value of the function script through a shared cache variable
I thought about the downside of this approach:
- maybe a timing issue if the shared cache variable is getting created after rules.Runrule() is finished?
- If the function script returns early because of an error and the return value (cache variable) already exists because of an earlier call (could be minimized by explicitly deleting the shared cache variable by the main script)
- if the function script is called almost simultaneously by two different scripts the shared cache variable could only be created once (solution would be to prefix the return value by a unique prefix (like ruleUID of the main script)
But I can’t see any major obstacles. What is your opinion?