Add mode to stored rules output

This commit is contained in:
2023-02-08 18:26:40 +00:00
parent 7e78c2857e
commit 1b1dbbc76c
4 changed files with 24 additions and 7 deletions

View File

@@ -1,8 +1,10 @@
import msgpack
from asgiref.sync import async_to_sync
from django.core.management.base import BaseCommand
from redis import StrictRedis
from core.lib.rules import rule_notify
from core.db.storage import db
from core.lib.rules import NotificationRuleData
from core.models import NotificationRule
from core.util import logs
@@ -79,7 +81,15 @@ def process_rules(data):
# Subtract 2, 1 for source and 1 for index
if matched_field_number == rule_field_length - 2:
meta = {"matched": matched, "total_hits": 1}
rule_notify(rule, index, message, meta=meta)
# Parse the rule, we saved some work above to avoid doing this,
# but it makes delivering messages significantly easier as we ca
# use the same code as for scheduling.
rule_data_object = NotificationRuleData(rule.user, rule, db=db)
# rule_notify(rule, index, message, meta=meta)
print("ABOUT TO RUN ASYNC TO SYNC")
rule_matched = async_to_sync(rule_data_object.rule_matched)
rule_matched(index, message, meta=meta, mode="ondemand")
class Command(BaseCommand):