nezha/service/dao/dao.go

57 lines
1.1 KiB
Go
Raw Normal View History

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"
"github.com/robfig/cron/v3"
"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-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
var SortedServerList []*model.Server
var SortedServerLock sync.RWMutex
// 计划任务相关
var CronLock sync.RWMutex
var Crons map[uint64]*model.Cron
var Cron *cron.Cron
var Version = "v0.3.8"
2021-01-08 08:04:50 -05:00
func ReSortServer() {
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 {
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
})
}