2019-12-08 03:59:58 -05:00
|
|
|
package dao
|
|
|
|
|
|
|
|
import (
|
2021-01-08 08:04:50 -05:00
|
|
|
"sort"
|
2019-12-09 05:14:31 -05:00
|
|
|
"sync"
|
|
|
|
|
2019-12-08 03:59:58 -05:00
|
|
|
"github.com/patrickmn/go-cache"
|
2021-01-18 20:59:04 -05:00
|
|
|
"github.com/robfig/cron/v3"
|
2020-12-19 10:11:16 -05:00
|
|
|
"gorm.io/gorm"
|
2019-12-08 03:59:58 -05:00
|
|
|
|
2020-11-10 21:07:45 -05:00
|
|
|
"github.com/naiba/nezha/model"
|
2019-12-08 03:59:58 -05:00
|
|
|
)
|
|
|
|
|
2020-12-19 23:18:27 -05:00
|
|
|
const (
|
|
|
|
SnapshotDelay = 3
|
|
|
|
ReportDelay = 2
|
|
|
|
)
|
|
|
|
|
2019-12-08 03:59:58 -05:00
|
|
|
var Conf *model.Config
|
|
|
|
|
|
|
|
var Cache *cache.Cache
|
|
|
|
|
|
|
|
var DB *gorm.DB
|
|
|
|
|
2021-01-18 20:59:04 -05:00
|
|
|
// 服务器监控、状态相关
|
2021-01-08 08:04:50 -05:00
|
|
|
var ServerList map[uint64]*model.Server
|
2019-12-09 05:14:31 -05:00
|
|
|
var ServerLock sync.RWMutex
|
2019-12-09 10:45:23 -05:00
|
|
|
|
2021-01-17 09:18:36 -05:00
|
|
|
var SortedServerList []*model.Server
|
|
|
|
var SortedServerLock sync.RWMutex
|
|
|
|
|
2021-01-18 20:59:04 -05:00
|
|
|
// 计划任务相关
|
|
|
|
var CronLock sync.RWMutex
|
|
|
|
var Crons map[uint64]*model.Cron
|
|
|
|
var Cron *cron.Cron
|
|
|
|
|
2021-01-23 05:15:11 -05:00
|
|
|
var Version = "v0.3.8"
|
2021-01-18 20:59:04 -05:00
|
|
|
|
2021-01-08 08:04:50 -05:00
|
|
|
func ReSortServer() {
|
2021-01-17 09:18:36 -05:00
|
|
|
ServerLock.RLock()
|
|
|
|
defer ServerLock.RUnlock()
|
|
|
|
SortedServerLock.Lock()
|
|
|
|
defer SortedServerLock.Unlock()
|
|
|
|
|
2021-01-08 08:04:50 -05:00
|
|
|
SortedServerList = []*model.Server{}
|
|
|
|
for _, s := range ServerList {
|
|
|
|
SortedServerList = append(SortedServerList, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.SliceStable(SortedServerList, func(i, j int) bool {
|
2021-01-20 06:24:59 -05:00
|
|
|
if SortedServerList[i].DisplayIndex == SortedServerList[j].DisplayIndex {
|
|
|
|
return SortedServerList[i].ID < SortedServerList[i].ID
|
|
|
|
}
|
2021-01-08 08:04:50 -05:00
|
|
|
return SortedServerList[i].DisplayIndex > SortedServerList[j].DisplayIndex
|
|
|
|
})
|
|
|
|
}
|