debeir.engines.client
1import dataclasses 2 3from elasticsearch import AsyncElasticsearch 4 5 6@dataclasses.dataclass(init=True) 7class Client: 8 """ 9 Overarching client interface object that contains references to different clients for search 10 Allows sharing between function calls 11 """ 12 es_client: AsyncElasticsearch = None 13 solr_client: object = None 14 generic_client: object = None 15 16 @classmethod 17 def build_from_config(cls, engine_type, engine_config) -> 'Client': 18 """ 19 Build client from engine config 20 :param engine_type: 21 :param engine_config: 22 :return: 23 """ 24 25 client = Client() 26 27 if engine_type == "elasticsearch": 28 es_client = AsyncElasticsearch( 29 f"{engine_config.protocol}://{engine_config.ip}:{engine_config.port}", 30 timeout=engine_config.timeout 31 ) 32 33 client.es_client = es_client 34 35 return client 36 37 def get_client(self, engine): 38 if engine == "elasticsearch": 39 return self.es_client 40 41 async def close(self): 42 """ 43 Generically close all contained client objects 44 """ 45 if self.es_client: 46 await self.es_client.close() 47 48 if self.solr_client: 49 await self.solr_client.close() 50 51 if self.generic_client: 52 await self.generic_client.close()
@dataclasses.dataclass(init=True)
class
Client:
7@dataclasses.dataclass(init=True) 8class Client: 9 """ 10 Overarching client interface object that contains references to different clients for search 11 Allows sharing between function calls 12 """ 13 es_client: AsyncElasticsearch = None 14 solr_client: object = None 15 generic_client: object = None 16 17 @classmethod 18 def build_from_config(cls, engine_type, engine_config) -> 'Client': 19 """ 20 Build client from engine config 21 :param engine_type: 22 :param engine_config: 23 :return: 24 """ 25 26 client = Client() 27 28 if engine_type == "elasticsearch": 29 es_client = AsyncElasticsearch( 30 f"{engine_config.protocol}://{engine_config.ip}:{engine_config.port}", 31 timeout=engine_config.timeout 32 ) 33 34 client.es_client = es_client 35 36 return client 37 38 def get_client(self, engine): 39 if engine == "elasticsearch": 40 return self.es_client 41 42 async def close(self): 43 """ 44 Generically close all contained client objects 45 """ 46 if self.es_client: 47 await self.es_client.close() 48 49 if self.solr_client: 50 await self.solr_client.close() 51 52 if self.generic_client: 53 await self.generic_client.close()
Overarching client interface object that contains references to different clients for search Allows sharing between function calls
Client( es_client: elasticsearch.AsyncElasticsearch = None, solr_client: object = None, generic_client: object = None)
@classmethod
def
build_from_config(cls, engine_type, engine_config) -> debeir.engines.client.Client:
17 @classmethod 18 def build_from_config(cls, engine_type, engine_config) -> 'Client': 19 """ 20 Build client from engine config 21 :param engine_type: 22 :param engine_config: 23 :return: 24 """ 25 26 client = Client() 27 28 if engine_type == "elasticsearch": 29 es_client = AsyncElasticsearch( 30 f"{engine_config.protocol}://{engine_config.ip}:{engine_config.port}", 31 timeout=engine_config.timeout 32 ) 33 34 client.es_client = es_client 35 36 return client
Build client from engine config
Parameters
- engine_type:
- engine_config:
Returns
async def
close(self):
42 async def close(self): 43 """ 44 Generically close all contained client objects 45 """ 46 if self.es_client: 47 await self.es_client.close() 48 49 if self.solr_client: 50 await self.solr_client.close() 51 52 if self.generic_client: 53 await self.generic_client.close()
Generically close all contained client objects