fix(server): add server status handling based on last reported time

This commit is contained in:
Chang lue Tsen
2025-09-02 14:38:53 -04:00
parent 3e5284c4ec
commit ca344a1ce9
4 changed files with 18 additions and 3 deletions
@@ -2,6 +2,7 @@ package server
import (
"context"
"time"
"github.com/perfect-panel/server/internal/model/node"
"github.com/perfect-panel/server/internal/svc"
@@ -68,6 +69,7 @@ func (l *FilterServerListLogic) FilterServerList(req *types.FilterServerListRequ
Cpu: nodeStatus.Cpu,
Disk: nodeStatus.Disk,
Online: l.handlerServerStatus(datum.Id, protocols),
Status: l.handlerServerStaus(datum.LastReportedAt),
}
list = append(list, server)
}
@@ -146,3 +148,17 @@ func (l *FilterServerListLogic) handlerServerStatus(id int64, protocols []types.
}
return result
}
func (l *FilterServerListLogic) handlerServerStaus(last *time.Time) string {
if last == nil {
return "offline"
}
if time.Since(*last) > time.Minute*5 {
return "offline"
}
if time.Since(*last) > time.Minute*3 {
return "warning"
}
return "online"
}