git忽略__debug
This commit is contained in:
Akizon77
2025-07-08 15:08:17 +08:00
parent 61ecf7858a
commit 2cecb92440
2 changed files with 46 additions and 31 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
__debug*
agent.json
.vscode/
komari-agent.exe

View File

@@ -33,11 +33,15 @@ func EstablishWebSocketConnection() {
interval = flags.Interval - 1
}
ticker := time.NewTicker(time.Duration(interval * float64(time.Second)))
defer ticker.Stop()
dataTicker := time.NewTicker(time.Duration(interval * float64(time.Second)))
defer dataTicker.Stop()
for range ticker.C {
// If no connection, attempt to connect
heartbeatTicker := time.NewTicker(30 * time.Second)
defer heartbeatTicker.Stop()
for {
select {
case <-dataTicker.C:
if conn == nil {
log.Println("Attempting to connect to WebSocket...")
retry := 0
@@ -71,6 +75,16 @@ func EstablishWebSocketConnection() {
conn = nil // Mark connection as dead
continue
}
case <-heartbeatTicker.C:
if conn != nil {
err := conn.WriteMessage(websocket.PingMessage, nil)
if err != nil {
log.Println("Failed to send heartbeat:", err)
conn.Close()
conn = nil // Mark connection as dead
}
}
}
}
}