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

@@ -280,6 +280,20 @@ class ElasticsearchBackend(StorageBackend):
self.log.error(f"Indexing failed: {result}")
self.log.debug(f"Indexed {len(matches)} messages in ES")
def store_matches(self, matches):
"""
Store a list of matches in Elasticsearch.
:param index: The index to store the matches in.
:param matches: A list of matches to store.
"""
if self.client is None:
self.initialise()
for match in matches:
result = self.client.index(index=settings.INDEX_RULE_STORAGE, body=match)
if not result["result"] == "created":
self.log.error(f"Indexing failed: {result}")
self.log.debug(f"Indexed {len(matches)} messages in ES")
async def schedule_query_results(self, rule_object):
"""
Helper to run a scheduled query with reduced functionality and async.