fixed server status uptime for coldeve
This commit is contained in:
parent
ca12f4807b
commit
72de9b0f7f
3 changed files with 56 additions and 39 deletions
|
|
@ -43,6 +43,7 @@ services:
|
||||||
POSTGRES_DB: dereth
|
POSTGRES_DB: dereth
|
||||||
POSTGRES_USER: postgres
|
POSTGRES_USER: postgres
|
||||||
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
|
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
|
||||||
|
DB_RETENTION_DAYS: 30
|
||||||
volumes:
|
volumes:
|
||||||
- timescale-data:/var/lib/postgresql/data
|
- timescale-data:/var/lib/postgresql/data
|
||||||
ports:
|
ports:
|
||||||
|
|
|
||||||
26
main.py
26
main.py
|
|
@ -171,11 +171,16 @@ AC_LOGIN_PACKET = bytes([
|
||||||
])
|
])
|
||||||
|
|
||||||
async def check_server_health(address: str, port: int, timeout: float = 3.0) -> tuple[bool, float, int]:
|
async def check_server_health(address: str, port: int, timeout: float = 3.0) -> tuple[bool, float, int]:
|
||||||
"""Check AC server health via UDP packet.
|
"""Check AC server health via UDP packet with retry logic.
|
||||||
|
|
||||||
|
Retries 6 times with 5-second delays before declaring server down.
|
||||||
Returns: (is_up, latency_ms, player_count)
|
Returns: (is_up, latency_ms, player_count)
|
||||||
"""
|
"""
|
||||||
logger.debug(f"🔍 Starting health check for {address}:{port}")
|
max_retries = 6
|
||||||
|
retry_delay = 5.0
|
||||||
|
|
||||||
|
for attempt in range(max_retries):
|
||||||
|
logger.debug(f"🔍 Health check attempt {attempt + 1}/{max_retries} for {address}:{port}")
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
sock.setblocking(False)
|
sock.setblocking(False)
|
||||||
|
|
@ -210,15 +215,24 @@ async def check_server_health(address: str, port: int, timeout: float = 3.0) ->
|
||||||
return True, latency_ms, None
|
return True, latency_ms, None
|
||||||
|
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
logger.debug(f"⏰ TIMEOUT: No response from {address}:{port} after {timeout}s - server down")
|
logger.debug(f"⏰ TIMEOUT: No response from {address}:{port} after {timeout}s")
|
||||||
return False, None, None
|
if attempt < max_retries - 1:
|
||||||
|
logger.debug(f"Retrying in {retry_delay} seconds...")
|
||||||
|
await asyncio.sleep(retry_delay)
|
||||||
|
continue
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Server health check error: {e}")
|
logger.error(f"Server health check error on attempt {attempt + 1}: {e}")
|
||||||
return False, None, None
|
if attempt < max_retries - 1:
|
||||||
|
await asyncio.sleep(retry_delay)
|
||||||
|
continue
|
||||||
finally:
|
finally:
|
||||||
sock.close()
|
sock.close()
|
||||||
|
|
||||||
|
# Only declare down after all retries fail
|
||||||
|
logger.warning(f"❌ Server {address}:{port} is DOWN after {max_retries} attempts over {max_retries * retry_delay} seconds")
|
||||||
|
return False, None, None
|
||||||
|
|
||||||
async def get_player_count_from_treestats(server_name: str) -> int:
|
async def get_player_count_from_treestats(server_name: str) -> int:
|
||||||
"""Get player count from TreeStats.net API (same as ThwargLauncher)."""
|
"""Get player count from TreeStats.net API (same as ThwargLauncher)."""
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ body {
|
||||||
font-family: "Segoe UI", sans-serif;
|
font-family: "Segoe UI", sans-serif;
|
||||||
background: var(--bg-main);
|
background: var(--bg-main);
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sort-buttons {
|
.sort-buttons {
|
||||||
|
|
@ -1450,3 +1451,4 @@ body.noselect, body.noselect * {
|
||||||
.regular-spell {
|
.regular-spell {
|
||||||
color: #88ccff;
|
color: #88ccff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue