feat(system-info): add stale instance cleanup actions (#5953)

This commit is contained in:
Seefs
2026-07-07 21:22:49 +08:00
committed by GitHub
parent fc1259f583
commit a72e5082e9
12 changed files with 411 additions and 82 deletions
+35
View File
@@ -2,6 +2,7 @@ package controller
import (
"net/http"
"strings"
"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/model"
@@ -28,3 +29,37 @@ func ListSystemInstances(c *gin.Context) {
"data": responses,
})
}
func DeleteStaleSystemInstances(c *gin.Context) {
deletedCount, err := model.DeleteStaleSystemInstances(common.GetTimestamp())
if err != nil {
common.ApiError(c, err)
return
}
common.ApiSuccess(c, gin.H{
"deleted_count": deletedCount,
})
}
func DeleteStaleSystemInstance(c *gin.Context) {
nodeName := c.Param("node_name")
if strings.TrimSpace(nodeName) == "" {
common.ApiErrorMsg(c, "node name is required")
return
}
deleted, err := model.DeleteStaleSystemInstance(nodeName, common.GetTimestamp())
if err != nil {
common.ApiError(c, err)
return
}
if !deleted {
common.ApiErrorMsg(c, "instance is not stale or no longer exists")
return
}
common.ApiSuccess(c, gin.H{
"deleted_count": 1,
})
}