Create sync versions of pathway to ingest messages to work around sync-only Django management commands

This commit is contained in:
2023-02-09 07:20:45 +00:00
parent 1b1dbbc76c
commit f0455984ef
3 changed files with 57 additions and 12 deletions

View File

@@ -1,5 +1,4 @@
import msgpack
from asgiref.sync import async_to_sync
from django.core.management.base import BaseCommand
from redis import StrictRedis
@@ -83,13 +82,13 @@ def process_rules(data):
meta = {"matched": matched, "total_hits": 1}
# Parse the rule, we saved some work above to avoid doing this,
# but it makes delivering messages significantly easier as we ca
# but it makes delivering messages significantly easier as we can
# 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")
rule_data_object.rule_matched_sync(
index, message, meta=meta, mode="ondemand"
)
class Command(BaseCommand):