优化忽略规则配置和 Agent 获取 IP

This commit is contained in:
naiba
2021-06-21 21:30:42 +08:00
parent c4f36d17d5
commit 4b0c0ad288
20 changed files with 370 additions and 291 deletions

View File

@@ -13,7 +13,7 @@ import (
pb "github.com/naiba/nezha/proto"
)
var Version = "v0.7.4" // !!记得修改 README 中的 badge 版本!!
var Version = "v0.8.0" // !!记得修改 README 中的 badge 版本!!
const (
SnapshotDelay = 3
@@ -58,7 +58,7 @@ var CronLock sync.RWMutex
var Crons map[uint64]*model.Cron
var Cron *cron.Cron
func CronTrigger(c *model.Cron) {
func ManualTrigger(c *model.Cron) {
ServerLock.RLock()
defer ServerLock.RUnlock()
for j := 0; j < len(c.Servers); j++ {
@@ -73,3 +73,31 @@ func CronTrigger(c *model.Cron) {
}
}
}
func CronTrigger(cr model.Cron) func() {
crIgnoreMap := make(map[uint64]bool)
for j := 0; j < len(cr.Servers); j++ {
crIgnoreMap[cr.Servers[j]] = true
}
return func() {
ServerLock.RLock()
defer ServerLock.RUnlock()
for _, s := range ServerList {
if cr.Cover == model.CronCoverAll && crIgnoreMap[s.ID] {
continue
}
if cr.Cover == model.CronCoverIgnoreAll && !crIgnoreMap[s.ID] {
continue
}
if s.TaskStream != nil {
s.TaskStream.Send(&pb.Task{
Id: cr.ID,
Data: cr.Command,
Type: model.TaskTypeCommand,
})
} else {
SendNotification(fmt.Sprintf("计划任务:%s服务器%s 离线,无法执行。", cr.Name, s.Name), false)
}
}
}
}