fix(watchdog): now the client could successfully send more msgs to watchdog instead of the only connection msg
- Add debug logging for watchdog operations - Standardize message format for instance operations - Improve TCP message handling with proper line termination - Enhance error handling in watchdog operations - Add proper cleanup of recvChan in sendMsg - Update response handling in instance handlers
This commit is contained in:
+30
-4
@@ -2,23 +2,45 @@ package watchdog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"super-frpc/postLog"
|
||||
)
|
||||
|
||||
func AddInstance(serviceName string) bool {
|
||||
postLog.Debug(fmt.Sprintf("[watchdog] Add service monitor: %s", serviceName))
|
||||
if !IsConnected() {
|
||||
return false
|
||||
}
|
||||
|
||||
message := fmt.Sprintf("[instance.add] <serviceName>%s</serviceName>", serviceName)
|
||||
message := fmt.Sprintf("[monitor.add] <serviceName>%s</serviceName>", serviceName)
|
||||
response, err := sendMsg(message, 3)
|
||||
if err != nil {
|
||||
return false
|
||||
} else if response == "success" {
|
||||
return true
|
||||
}
|
||||
|
||||
return response == "success"
|
||||
return false
|
||||
}
|
||||
|
||||
func RemoveInstance(serviceName string) bool {
|
||||
postLog.Debug(fmt.Sprintf("[watchdog] Remove service monitor: %s", serviceName))
|
||||
if !IsConnected() {
|
||||
return false
|
||||
}
|
||||
|
||||
message := fmt.Sprintf("[monitor.remove] <serviceName>%s</serviceName>", serviceName)
|
||||
response, err := sendMsg(message, 3)
|
||||
if err != nil {
|
||||
return false
|
||||
} else if response == "success" {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func CloseInstance(serviceName string) bool {
|
||||
postLog.Debug(fmt.Sprintf("[watchdog] Remove service monitor: %s", serviceName))
|
||||
if !IsConnected() {
|
||||
return false
|
||||
}
|
||||
@@ -27,9 +49,11 @@ func RemoveInstance(serviceName string) bool {
|
||||
response, err := sendMsg(message, 3)
|
||||
if err != nil {
|
||||
return false
|
||||
} else if response == "success" {
|
||||
return true
|
||||
}
|
||||
|
||||
return response == "success"
|
||||
return false
|
||||
}
|
||||
|
||||
func Close() bool {
|
||||
@@ -41,7 +65,9 @@ func Close() bool {
|
||||
response, err := sendMsg(message, 3)
|
||||
if err != nil {
|
||||
return false
|
||||
} else if response == "success" {
|
||||
return true
|
||||
}
|
||||
|
||||
return response == "success"
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user