|
32 | 32 | from graphql import validate as validate_graphql |
33 | 33 | from jsonschema import validate |
34 | 34 | from memphis.consumer import Consumer |
35 | | -from memphis.exceptions import MemphisConnectError, MemphisError, MemphisHeaderError |
| 35 | +from memphis.exceptions import MemphisConnectError, MemphisError, MemphisHeaderError, MemphisSchemaError |
36 | 36 | from memphis.headers import Headers |
37 | 37 | from memphis.producer import Producer |
38 | 38 | from memphis.station import Station |
|
42 | 42 |
|
43 | 43 | class Memphis: |
44 | 44 | MAX_BATCH_SIZE = 5000 |
| 45 | + MEMPHIS_GLOBAL_ACCOUNT_NAME = "$memphis" |
45 | 46 | def __init__(self): |
46 | 47 | self.is_connection_active = False |
47 | 48 | self.schema_updates_data = {} |
@@ -90,6 +91,31 @@ async def sdk_client_updates_listener(self): |
90 | 91 | self.configuration_tasks = task |
91 | 92 | except Exception as err: |
92 | 93 | raise MemphisError(err) |
| 94 | + |
| 95 | + async def get_tenant_name(self, account_id): |
| 96 | + try: |
| 97 | + getTenantNameReq = { |
| 98 | + "tenant_id": account_id |
| 99 | + } |
| 100 | + get_tenant_id_req_bytes = json.dumps(getTenantNameReq, indent=2).encode("utf-8") |
| 101 | + err_msg = await self.broker_manager.request( |
| 102 | + "$memphis_get_tenant_name", get_tenant_id_req_bytes, timeout=5 |
| 103 | + ) |
| 104 | + tenant_name_response = err_msg.data.decode("utf-8") |
| 105 | + tenant_name_response = json.loads(tenant_name_response) |
| 106 | + |
| 107 | + if tenant_name_response['error'] != "": |
| 108 | + raise MemphisError(tenant_name_response['error']) |
| 109 | + |
| 110 | + return tenant_name_response["tenant_name"] |
| 111 | + |
| 112 | + except Exception as err: |
| 113 | + # for backward compatibility |
| 114 | + if err.__class__.__name__ == 'NoRespondersError': |
| 115 | + return self.MEMPHIS_GLOBAL_ACCOUNT_NAME |
| 116 | + else: |
| 117 | + raise MemphisError(err) |
| 118 | + |
93 | 119 |
|
94 | 120 | async def connect( |
95 | 121 | self, |
@@ -170,6 +196,7 @@ async def connect( |
170 | 196 | await self.sdk_client_updates_listener() |
171 | 197 | self.broker_connection = self.broker_manager.jetstream() |
172 | 198 | self.is_connection_active = True |
| 199 | + self.tenant_name = await self.get_tenant_name(self.account_id) |
173 | 200 | except Exception as e: |
174 | 201 | raise MemphisError(str(e)) |
175 | 202 |
|
|
0 commit comments