fix(watchdog): integrate instance management with watchdog

Add watchdog instance management in Start/StopInstanceHandler to sync with watchdog service
Add notification enabled check in exceptionHandle function
This commit is contained in:
2026-04-28 19:50:52 +08:00
parent 0890c8136f
commit 8108d4d01f
2 changed files with 58 additions and 26 deletions
+35 -8
View File
@@ -16,6 +16,8 @@ import (
"super-frpc/utils"
"super-frpc/postLog"
"super-frpc/service"
"super-frpc/watchdog"
"super-frpc/global"
)
func CreateInstanceHandler(w http.ResponseWriter, r *http.Request) {
@@ -626,10 +628,23 @@ func StartInstanceHandler(w http.ResponseWriter, r *http.Request) {
return
}
utils.SendSuccessResponse(w, "Instance started successfully", map[string]interface{}{
"instanceID": instanceID,
"serviceName": serviceName,
})
if global.Is.WatchdogConnected {
if !watchdog.AddInstance(serviceName) {
postLog.Warning(fmt.Sprintf("[StartInstanceHandler] Failed to add watchdog instance %s", serviceName))
utils.SendSuccessResponse(w, "Instance started successfully but watchdog instance add failed", map[string]interface{}{
"instanceID": instanceID,
"serviceName": serviceName,
})
return
} else {
utils.SendSuccessResponse(w, "Instance started successfully", map[string]interface{}{
"instanceID": instanceID,
"serviceName": serviceName,
})
}
}
postLog.Info(fmt.Sprintf("[StartInstanceHandler] Instance %d started successfully", instanceID))
}
@@ -724,10 +739,22 @@ func StopInstanceHandler(w http.ResponseWriter, r *http.Request) {
return
}
utils.SendSuccessResponse(w, "Instance stopped successfully", map[string]interface{}{
"instanceID": instanceID,
"serviceName": serviceName,
})
if global.Is.WatchdogConnected {
if !watchdog.RemoveInstance(serviceName) {
postLog.Warning(fmt.Sprintf("[StopInstanceHandler] Failed to remove watchdog instance %s", serviceName))
utils.SendSuccessResponse(w, "Instance stopped successfully but watchdog instance remove failed", map[string]interface{}{
"instanceID": instanceID,
"serviceName": serviceName,
})
} else {
utils.SendSuccessResponse(w, "Instance stopped successfully", map[string]interface{}{
"instanceID": instanceID,
"serviceName": serviceName,
})
}
}
postLog.Info(fmt.Sprintf("[StopInstanceHandler] Instance %d stopped successfully", instanceID))
}