Begin refactoring Elastic backend to use helper functions
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import datetime
|
||||
from math import floor, log10
|
||||
|
||||
@@ -14,7 +15,7 @@ from core.util import logs
|
||||
from core.views import helpers
|
||||
|
||||
|
||||
class StorageBackend(object):
|
||||
class StorageBackend(ABC):
|
||||
def __init__(self, name):
|
||||
self.log = logs.get_logger(name)
|
||||
self.log.info(f"Initialising storage backend {name}")
|
||||
@@ -22,8 +23,9 @@ class StorageBackend(object):
|
||||
self.initialise_caching()
|
||||
self.initialise()
|
||||
|
||||
@abstractmethod
|
||||
def initialise(self, **kwargs):
|
||||
raise NotImplementedError
|
||||
pass
|
||||
|
||||
def initialise_caching(self):
|
||||
hash_key = r.get("cache_hash_key")
|
||||
@@ -37,11 +39,13 @@ class StorageBackend(object):
|
||||
self.log.debug(f"Decoded hash key: {hash_key}")
|
||||
self.hash_key = hash_key
|
||||
|
||||
@abstractmethod
|
||||
def construct_query(self, **kwargs):
|
||||
raise NotImplementedError
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def run_query(self, **kwargs):
|
||||
raise NotImplementedError
|
||||
pass
|
||||
|
||||
def parse_size(self, query_params, sizes):
|
||||
if "size" in query_params:
|
||||
@@ -308,8 +312,9 @@ class StorageBackend(object):
|
||||
time_took_rounded = round(time_took, 3 - int(floor(log10(abs(time_took)))) - 1)
|
||||
return {"object_list": response_parsed, "took": time_took_rounded}
|
||||
|
||||
@abstractmethod
|
||||
def query_results(self, **kwargs):
|
||||
raise NotImplementedError
|
||||
pass
|
||||
|
||||
def process_results(self, response, **kwargs):
|
||||
if kwargs.get("annotate"):
|
||||
@@ -321,5 +326,6 @@ class StorageBackend(object):
|
||||
dedup_fields = ["msg", "nick", "ident", "host", "net", "channel"]
|
||||
response = helpers.dedup_list(response, dedup_fields)
|
||||
|
||||
@abstractmethod
|
||||
def parse(self, response):
|
||||
raise NotImplementedError
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user