We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dbce178 commit fe8ce60Copy full SHA for fe8ce60
service/singleton/server.go
@@ -4,6 +4,7 @@ import (
4
"log"
5
"sort"
6
"sync"
7
+ "time"
8
9
"github.com/jinzhu/copier"
10
"github.com/xos/serverstatus/model"
@@ -41,6 +42,14 @@ func loadServers() {
41
42
innerS.LastStateBeforeOffline = nil
43
innerS.IsOnline = false // 初始状态为离线,等待agent报告
44
45
+ // 从数据库恢复LastActive时间,使用LastOnline字段
46
+ if !innerS.LastOnline.IsZero() {
47
+ innerS.LastActive = innerS.LastOnline
48
+ } else {
49
+ // 如果没有LastOnline记录,设置为当前时间减去一个较大的值,表示很久没有活动
50
+ innerS.LastActive = time.Now().Add(-24 * time.Hour)
51
+ }
52
+
53
// 从数据库加载Host信息
54
var hostJSONStr string
55
if err := DB.Raw("SELECT host_json FROM servers WHERE id = ?", innerS.ID).Scan(&hostJSONStr).Error; err == nil && len(hostJSONStr) > 0 {
0 commit comments