mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48: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。
|
||||
|
||||
|
@ -75,13 +75,13 @@ func (ma *memberAPI) delete(c *gin.Context) {
|
||||
err = dao.DB.Delete(&model.MonitorHistory{}, "monitor_id = ?", id).Error
|
||||
}
|
||||
case "cron":
|
||||
|
||||
err = dao.DB.Delete(&model.Cron{}, "id = ?", id).Error
|
||||
if err == nil {
|
||||
dao.CronLock.RLock()
|
||||
defer dao.CronLock.RUnlock()
|
||||
if dao.Crons[id].CronID != 0 {
|
||||
dao.Cron.Remove(dao.Crons[id].CronID)
|
||||
cr := dao.Crons[id]
|
||||
if cr != nil && cr.CronID != 0 {
|
||||
dao.Cron.Remove(cr.CronID)
|
||||
}
|
||||
delete(dao.Crons, id)
|
||||
}
|
||||
@ -264,13 +264,15 @@ func (ma *memberAPI) addOrEditCron(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if cr.CronID != 0 {
|
||||
dao.Cron.Remove(cr.CronID)
|
||||
dao.ServerLock.Lock()
|
||||
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() {
|
||||
dao.ServerLock.RLock()
|
||||
defer dao.ServerLock.RUnlock()
|
||||
for j := 0; j < len(cr.Servers); j++ {
|
||||
if dao.ServerList[cr.Servers[j]].TaskStream != nil {
|
||||
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{
|
||||
Code: http.StatusOK,
|
||||
})
|
||||
|
@ -34,7 +34,7 @@ var CronLock sync.RWMutex
|
||||
var Crons map[uint64]*model.Cron
|
||||
var Cron *cron.Cron
|
||||
|
||||
var Version = "v0.3.6"
|
||||
var Version = "v0.3.7"
|
||||
|
||||
func ReSortServer() {
|
||||
ServerLock.RLock()
|
||||
|
@ -58,18 +58,20 @@ func (s *NezhaHandler) ReportTask(c context.Context, r *pb.TaskResult) (*pb.Rece
|
||||
if r.GetType() == model.TaskTypeCommand {
|
||||
// 处理上报的计划任务
|
||||
dao.CronLock.RLock()
|
||||
defer dao.CronLock.RUnlock()
|
||||
cr := dao.Crons[r.GetId()]
|
||||
dao.CronLock.RUnlock()
|
||||
if cr.PushSuccessful && r.GetSuccessful() {
|
||||
alertmanager.SendNotification(fmt.Sprintf("成功计划任务:%s ,服务器:%d,日志:\n%s", cr.Name, clientID, r.GetData()))
|
||||
if cr != nil {
|
||||
if cr.PushSuccessful && r.GetSuccessful() {
|
||||
alertmanager.SendNotification(fmt.Sprintf("成功计划任务:%s ,服务器:%d,日志:\n%s", cr.Name, clientID, r.GetData()))
|
||||
}
|
||||
if !r.GetSuccessful() {
|
||||
alertmanager.SendNotification(fmt.Sprintf("失败计划任务:%s ,服务器:%d,日志:\n%s", cr.Name, clientID, r.GetData()))
|
||||
}
|
||||
dao.DB.Model(cr).Updates(model.Cron{
|
||||
LastExecutedAt: time.Now().Add(time.Second * -1 * time.Duration(r.GetDelay())),
|
||||
LastResult: r.GetSuccessful(),
|
||||
})
|
||||
}
|
||||
if !r.GetSuccessful() {
|
||||
alertmanager.SendNotification(fmt.Sprintf("失败计划任务:%s ,服务器:%d,日志:\n%s", cr.Name, clientID, r.GetData()))
|
||||
}
|
||||
dao.DB.Model(cr).Updates(model.Cron{
|
||||
LastExecutedAt: time.Now().Add(time.Second * -1 * time.Duration(r.GetDelay())),
|
||||
LastResult: r.GetSuccessful(),
|
||||
})
|
||||
} else {
|
||||
// 存入历史记录
|
||||
mh := model.PB2MonitorHistory(r)
|
||||
|
Loading…
Reference in New Issue
Block a user