Skip to content
This repository has been archived by the owner on Feb 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #25 from ChatGPT-Hackers/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Cheong authored Dec 29, 2022
2 parents 694e89f + b6dc197 commit 7fba957
Showing 1 changed file with 0 additions and 8 deletions.
8 changes: 0 additions & 8 deletions handlers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func API_ask(c *gin.Context) {
// Find connection with the lowest load and where heartbeat is after last message time
connectionPool.Mu.RLock()
for _, conn := range connectionPool.Connections {
println(conn.Id)
if connection == nil || conn.LastMessageTime.Before(connection.LastMessageTime) {
if conn.Heartbeat.After(conn.LastMessageTime) {
connection = conn
Expand All @@ -90,17 +89,14 @@ func API_ask(c *gin.Context) {
return
}
// Ping before sending request
println(connection.Id)
var pingSucceeded bool = ping(connection.Id)
if !pingSucceeded {
// Ping failed. Try again
connectionPool.Delete(connection.Id)
println("Ping failed")
succeeded = false
connection = nil
continue
} else {
println("Ping succeeded")
succeeded = true
break
}
Expand Down Expand Up @@ -224,7 +220,6 @@ func API_getConnections(c *gin.Context) {
}

func ping(connection_id string) bool {
println("Starting ping")
// Get connection
connection, ok := connectionPool.Get(connection_id)
// Send "ping" to the connection
Expand All @@ -236,7 +231,6 @@ func ping(connection_id string) bool {
}
connection.Ws.SetReadDeadline(time.Now().Add(5 * time.Second))
err := connection.Ws.WriteJSON(send)
println("Sent ping")
if err != nil {
return false
}
Expand All @@ -245,9 +239,7 @@ func ping(connection_id string) bool {
// Read message
var receive types.Message
err = connection.Ws.ReadJSON(&receive)
println("Received ping response")
if err != nil {
println("There was an error")
return false
}
// Check if the message is the response
Expand Down

0 comments on commit 7fba957

Please sign in to comment.