Auto-update: Mon Aug 12 17:00:10 PDT 2024

This commit is contained in:
sanj 2024-08-12 17:00:10 -07:00
parent fd81cbed98
commit 0bc936dc47

View file

@ -408,13 +408,18 @@ class Database:
for server in self.config['POOL']: for server in self.config['POOL']:
if server['ts_id'] in online_servers and server['ts_id'] != self.local_ts_id: if server['ts_id'] in online_servers and server['ts_id'] != self.local_ts_id:
url = f"http://{server['ts_ip']}:{server['app_port']}/db/sync" url = f"http://{server['ts_ip']}:{server['app_port']}/db/sync"
tasks.append(self.call_db_sync(url)) tasks.append(self.call_db_sync(server))
await asyncio.gather(*tasks) await asyncio.gather(*tasks)
async def call_db_sync(self, url):
async def call_db_sync(self, server):
url = f"http://{server['ts_ip']}:{server['app_port']}/db/sync"
headers = {
"Authorization": f"Bearer {server['api_key']}"
}
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
try: try:
async with session.post(url, timeout=30) as response: async with session.post(url, headers=headers, timeout=30) as response:
if response.status == 200: if response.status == 200:
l.info(f"Successfully called /db/sync on {url}") l.info(f"Successfully called /db/sync on {url}")
else: else:
@ -424,6 +429,7 @@ class Database:
except Exception as e: except Exception as e:
l.error(f"Error calling /db/sync on {url}: {str(e)}") l.error(f"Error calling /db/sync on {url}: {str(e)}")
async def close(self): async def close(self):
for engine in self.engines.values(): for engine in self.engines.values():
await engine.dispose() await engine.dispose()