mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 20:58:14 -05:00
🐛 [dashboard v0.3.7] cron: 修复一些计划任务数据问题
This commit is contained in:
parent
d88c34da4e
commit
ed8dc18caa
@ -1,6 +1,6 @@
|
|||||||
# 哪吒面板
|
# 哪吒面板
|
||||||
|
|
||||||
![dashboard](https://img.shields.io/badge/管理面板-v0.3.6-brightgreen?style=for-the-badge&logo=github) ![Agent release](https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github)
|
![dashboard](https://img.shields.io/badge/管理面板-v0.3.7-brightgreen?style=for-the-badge&logo=github) ![Agent release](https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github)
|
||||||
|
|
||||||
系统状态监控报警、API(SSL证书变更、即将到期、到期)/TCP端口存活/PING 监控、计划任务(可以定时在Agent上执行命令,备份、重启、What ever you want)、极省资源,64M 服务器也能装 agent。
|
系统状态监控报警、API(SSL证书变更、即将到期、到期)/TCP端口存活/PING 监控、计划任务(可以定时在Agent上执行命令,备份、重启、What ever you want)、极省资源,64M 服务器也能装 agent。
|
||||||
|
|
||||||
|
@ -75,13 +75,13 @@ func (ma *memberAPI) delete(c *gin.Context) {
|
|||||||
err = dao.DB.Delete(&model.MonitorHistory{}, "monitor_id = ?", id).Error
|
err = dao.DB.Delete(&model.MonitorHistory{}, "monitor_id = ?", id).Error
|
||||||
}
|
}
|
||||||
case "cron":
|
case "cron":
|
||||||
|
|
||||||
err = dao.DB.Delete(&model.Cron{}, "id = ?", id).Error
|
err = dao.DB.Delete(&model.Cron{}, "id = ?", id).Error
|
||||||
if err == nil {
|
if err == nil {
|
||||||
dao.CronLock.RLock()
|
dao.CronLock.RLock()
|
||||||
defer dao.CronLock.RUnlock()
|
defer dao.CronLock.RUnlock()
|
||||||
if dao.Crons[id].CronID != 0 {
|
cr := dao.Crons[id]
|
||||||
dao.Cron.Remove(dao.Crons[id].CronID)
|
if cr != nil && cr.CronID != 0 {
|
||||||
|
dao.Cron.Remove(cr.CronID)
|
||||||
}
|
}
|
||||||
delete(dao.Crons, id)
|
delete(dao.Crons, id)
|
||||||
}
|
}
|
||||||
@ -264,13 +264,15 @@ func (ma *memberAPI) addOrEditCron(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if cr.CronID != 0 {
|
dao.ServerLock.Lock()
|
||||||
dao.Cron.Remove(cr.CronID)
|
defer dao.ServerLock.Unlock()
|
||||||
|
|
||||||
|
crOld := dao.Crons[cr.ID]
|
||||||
|
if crOld != nil && crOld.CronID != 0 {
|
||||||
|
dao.Cron.Remove(crOld.CronID)
|
||||||
}
|
}
|
||||||
|
|
||||||
cr.CronID, err = dao.Cron.AddFunc(cr.Scheduler, func() {
|
cr.CronID, err = dao.Cron.AddFunc(cr.Scheduler, func() {
|
||||||
dao.ServerLock.RLock()
|
|
||||||
defer dao.ServerLock.RUnlock()
|
|
||||||
for j := 0; j < len(cr.Servers); j++ {
|
for j := 0; j < len(cr.Servers); j++ {
|
||||||
if dao.ServerList[cr.Servers[j]].TaskStream != nil {
|
if dao.ServerList[cr.Servers[j]].TaskStream != nil {
|
||||||
dao.ServerList[cr.Servers[j]].TaskStream.Send(&pb.Task{
|
dao.ServerList[cr.Servers[j]].TaskStream.Send(&pb.Task{
|
||||||
@ -284,6 +286,9 @@ func (ma *memberAPI) addOrEditCron(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
delete(dao.Crons, cr.ID)
|
||||||
|
dao.Crons[cr.ID] = &cr
|
||||||
|
|
||||||
c.JSON(http.StatusOK, model.Response{
|
c.JSON(http.StatusOK, model.Response{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
})
|
})
|
||||||
|
@ -34,7 +34,7 @@ var CronLock sync.RWMutex
|
|||||||
var Crons map[uint64]*model.Cron
|
var Crons map[uint64]*model.Cron
|
||||||
var Cron *cron.Cron
|
var Cron *cron.Cron
|
||||||
|
|
||||||
var Version = "v0.3.6"
|
var Version = "v0.3.7"
|
||||||
|
|
||||||
func ReSortServer() {
|
func ReSortServer() {
|
||||||
ServerLock.RLock()
|
ServerLock.RLock()
|
||||||
|
@ -58,8 +58,9 @@ func (s *NezhaHandler) ReportTask(c context.Context, r *pb.TaskResult) (*pb.Rece
|
|||||||
if r.GetType() == model.TaskTypeCommand {
|
if r.GetType() == model.TaskTypeCommand {
|
||||||
// 处理上报的计划任务
|
// 处理上报的计划任务
|
||||||
dao.CronLock.RLock()
|
dao.CronLock.RLock()
|
||||||
|
defer dao.CronLock.RUnlock()
|
||||||
cr := dao.Crons[r.GetId()]
|
cr := dao.Crons[r.GetId()]
|
||||||
dao.CronLock.RUnlock()
|
if cr != nil {
|
||||||
if cr.PushSuccessful && r.GetSuccessful() {
|
if cr.PushSuccessful && r.GetSuccessful() {
|
||||||
alertmanager.SendNotification(fmt.Sprintf("成功计划任务:%s ,服务器:%d,日志:\n%s", cr.Name, clientID, r.GetData()))
|
alertmanager.SendNotification(fmt.Sprintf("成功计划任务:%s ,服务器:%d,日志:\n%s", cr.Name, clientID, r.GetData()))
|
||||||
}
|
}
|
||||||
@ -70,6 +71,7 @@ func (s *NezhaHandler) ReportTask(c context.Context, r *pb.TaskResult) (*pb.Rece
|
|||||||
LastExecutedAt: time.Now().Add(time.Second * -1 * time.Duration(r.GetDelay())),
|
LastExecutedAt: time.Now().Add(time.Second * -1 * time.Duration(r.GetDelay())),
|
||||||
LastResult: r.GetSuccessful(),
|
LastResult: r.GetSuccessful(),
|
||||||
})
|
})
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// 存入历史记录
|
// 存入历史记录
|
||||||
mh := model.PB2MonitorHistory(r)
|
mh := model.PB2MonitorHistory(r)
|
||||||
|
Loading…
Reference in New Issue
Block a user