[rules] Don't attempt to pre-compile disabled rules (#4329)

Fixes an issue, where an error that compilation failed for disabled rules.
Reported on the community: https://community.openhab.org/t/oh-4-2-snapshot-disabled-rules-failed-to-compile-error-in-opehab-log/157402.
Follow-up for #4289.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
This commit is contained in:
Florian Hotze 2024-07-24 20:18:49 +02:00 committed by GitHub
parent f502e9d4e3
commit e1574488b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1555,15 +1555,16 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
}
/**
* This method compiles the conditions and actions of all rules. It is called when the rule engine is started.
* This method compiles the conditions and actions of all enabled rules.
* It is called when the rule engine is started.
* By compiling when the rule engine is started, we make sure all conditions and actions are compiled, even if their
* handlers weren't available when the rule was added to the rule engine.
*/
private void compileRules() {
getScheduledExecutor().submit(() -> {
ruleRegistry.getAll().forEach(r -> {
compileRule(r.getUID());
});
ruleRegistry.getAll().stream() //
.filter(r -> isEnabled(r.getUID())) //
.forEach(r -> compileRule(r.getUID()));
executeRulesWithStartLevel();
});
}