Skip to content

Commit fe8ce60

Browse files
committed
Update.
1 parent dbce178 commit fe8ce60

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

service/singleton/server.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"log"
55
"sort"
66
"sync"
7+
"time"
78

89
"github.com/jinzhu/copier"
910
"github.com/xos/serverstatus/model"
@@ -41,6 +42,14 @@ func loadServers() {
4142
innerS.LastStateBeforeOffline = nil
4243
innerS.IsOnline = false // 初始状态为离线,等待agent报告
4344

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+
4453
// 从数据库加载Host信息
4554
var hostJSONStr string
4655
if err := DB.Raw("SELECT host_json FROM servers WHERE id = ?", innerS.ID).Scan(&hostJSONStr).Error; err == nil && len(hostJSONStr) > 0 {

0 commit comments

Comments
 (0)