From 376efabd546816cb7c7b764d57b7cbe84bcafe8d Mon Sep 17 00:00:00 2001 From: mananhai Date: Wed, 26 Oct 2022 14:57:33 +0800 Subject: [PATCH] Solve the bug that the flying book alarm fails --- common/pkg/notify/noticer.go | 4 ++++ node/internal/handler/job.go | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/common/pkg/notify/noticer.go b/common/pkg/notify/noticer.go index 9542090..fc92cfb 100644 --- a/common/pkg/notify/noticer.go +++ b/common/pkg/notify/noticer.go @@ -2,6 +2,7 @@ package notify import ( "github.com/tmnhs/crony/common/pkg/utils" + "strings" "time" ) @@ -64,4 +65,7 @@ func (m *Message) Check() { if m.OccurTime == "" { m.OccurTime = time.Now().Format(utils.TimeFormatSecond) } + //Remove the transfer character + m.Body = strings.Replace(m.Body, "\"", "'", -1) + m.Body = strings.Replace(m.Body, "\n", "", -1) } diff --git a/node/internal/handler/job.go b/node/internal/handler/job.go index b25fd1f..2d7302e 100644 --- a/node/internal/handler/job.go +++ b/node/internal/handler/job.go @@ -121,7 +121,7 @@ func (j *Job) RunWithRecovery() { Type: j.NotifyType, IP: fmt.Sprintf("%s:%s", node.IP, node.PID), Subject: fmt.Sprintf("任务[%s]立即执行失败", j.Name), - Body: strings.Replace(fmt.Sprintf("job[%d] run on node[%s] once execute failed ,output:%s,error:%s", j.ID, j.RunOn, result, runErr.Error()), "\n", "", -1), + Body: fmt.Sprintf("job[%d] run on node[%s] once execute failed ,output:%s,error:%s", j.ID, j.RunOn, result, runErr.Error()), To: to, OccurTime: time.Now().Format(utils.TimeFormatSecond), } @@ -167,7 +167,7 @@ func CreateJob(j *Job) cron.FuncJob { } i++ if i < execTimes { - logger.GetLogger().Warn(fmt.Sprintf("job execution failure#jobId-%d#retry%d次#output-%s#error-%v", j.ID, i, output, runErr)) + logger.GetLogger().Warn(fmt.Sprintf("job execution failure#jobId-%d#retry %d times #output-%s#error-%v", j.ID, i, output, runErr)) if j.RetryInterval > 0 { time.Sleep(time.Duration(j.RetryInterval) * time.Second) } else { @@ -202,7 +202,7 @@ func CreateJob(j *Job) cron.FuncJob { Type: j.NotifyType, IP: fmt.Sprintf("%s:%s", node.IP, node.PID), Subject: fmt.Sprintf("任务[%s]执行失败", j.Name), - Body: strings.Replace(fmt.Sprintf("job[%d] run on node[%s] execute failed ,retry %d times ,output :%s, error:%v", j.ID, j.RunOn, j.RetryTimes, output, runErr), "\n", "", -1), + Body: fmt.Sprintf("job[%d] run on node[%s] execute failed ,retry %d times ,output :%s, error:%v", j.ID, j.RunOn, j.RetryTimes, output, runErr), To: to, OccurTime: time.Now().Format(utils.TimeFormatSecond), }