Fix cluster client uptime to show time since last successful connection

- Update connected_at timestamp on each successful connection
- Uptime now resets to 00:00:00 on reconnections as expected
parent 54826337
......@@ -1662,25 +1662,13 @@ def save_cluster_client(client_id: str, token: str, hostname: str, ip_address: s
gpu_info = VALUES(gpu_info),
available_backends = VALUES(available_backends),
connected = 1,
connected_at = CURRENT_TIMESTAMP,
last_seen = CURRENT_TIMESTAMP
''', (client_id, token, hostname, ip_address, weight, gpu_info_json, available_backends_json))
else:
# For SQLite, preserve connected_at if client already exists
cursor.execute('SELECT connected_at FROM cluster_clients WHERE client_id = ?', (client_id,))
existing = cursor.fetchone()
if existing and existing['connected_at']:
# Update existing client, preserve connected_at
cursor.execute('''
UPDATE cluster_clients SET
hostname = ?, ip_address = ?, weight = ?, gpu_info = ?, available_backends = ?,
connected = 1, last_seen = CURRENT_TIMESTAMP
WHERE client_id = ?
''', (hostname, ip_address, weight, gpu_info_json, available_backends_json, client_id))
else:
# Insert new client
# For SQLite, update connected_at on each successful connection
cursor.execute('''
INSERT INTO cluster_clients
INSERT OR REPLACE INTO cluster_clients
(client_id, token, hostname, ip_address, weight, gpu_info, available_backends, connected, connected_at, last_seen)
VALUES (?, ?, ?, ?, ?, ?, ?, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
''', (client_id, token, hostname, ip_address, weight, gpu_info_json, available_backends_json))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment