diff --git a/application/src/main/java/org/thingsboard/server/service/notification/rule/DefaultNotificationRuleProcessor.java b/application/src/main/java/org/thingsboard/server/service/notification/rule/DefaultNotificationRuleProcessor.java index e9656f2ea6..70ba344b84 100644 --- a/application/src/main/java/org/thingsboard/server/service/notification/rule/DefaultNotificationRuleProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/notification/rule/DefaultNotificationRuleProcessor.java @@ -77,18 +77,17 @@ public class DefaultNotificationRuleProcessor implements NotificationRuleProcess public void process(NotificationRuleTrigger trigger) { NotificationRuleTriggerType triggerType = trigger.getType(); TenantId tenantId = triggerType.isTenantLevel() ? trigger.getTenantId() : TenantId.SYS_TENANT_ID; - - try { - List enabledRules = notificationRulesCache.getEnabled(tenantId, triggerType); - if (enabledRules.isEmpty()) { - return; - } - if (trigger.deduplicate()) { - enabledRules = new ArrayList<>(enabledRules); - enabledRules.removeIf(rule -> deduplicationService.alreadyProcessed(trigger, rule)); - } - final List rules = enabledRules; - notificationExecutor.submit(() -> { + notificationExecutor.submit(() -> { + try { + List enabledRules = notificationRulesCache.getEnabled(tenantId, triggerType); + if (enabledRules.isEmpty()) { + return; + } + if (trigger.deduplicate()) { + enabledRules = new ArrayList<>(enabledRules); + enabledRules.removeIf(rule -> deduplicationService.alreadyProcessed(trigger, rule)); + } + final List rules = enabledRules; for (NotificationRule rule : rules) { try { processNotificationRule(rule, trigger); @@ -96,10 +95,10 @@ public class DefaultNotificationRuleProcessor implements NotificationRuleProcess log.error("Failed to process notification rule {} for trigger type {} with trigger object {}", rule.getId(), rule.getTriggerType(), trigger, e); } } - }); - } catch (Throwable e) { - log.error("Failed to process notification rules for trigger: {}", trigger, e); - } + } catch (Throwable e) { + log.error("Failed to process notification rules for trigger: {}", trigger, e); + } + }); } private void processNotificationRule(NotificationRule rule, NotificationRuleTrigger trigger) {