From 8bd5e72d9998aaa4440487a3c192c3f98f78b552 Mon Sep 17 00:00:00 2001 From: chenjie Date: Mon, 3 Jul 2017 17:59:36 +0800 Subject: [PATCH] fix task edit problem when status is running --- app/controllers/task.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/controllers/task.go b/app/controllers/task.go index 7b3f7ac..7fcdc40 100644 --- a/app/controllers/task.go +++ b/app/controllers/task.go @@ -1,14 +1,15 @@ package controllers import ( + "strconv" + "strings" + "time" + "github.com/astaxie/beego" libcron "github.com/lisijie/cron" "github.com/lisijie/webcron/app/jobs" "github.com/lisijie/webcron/app/libs" "github.com/lisijie/webcron/app/models" - "strconv" - "strings" - "time" ) type TaskController struct { @@ -163,7 +164,18 @@ func (this *TaskController) Edit() { if err := task.Update(); err != nil { this.ajaxMsg(err.Error(), MSG_ERR) } - + if task.Status == 1 { + jobs.RemoveJob(id) + job, err := jobs.NewJobFromTask(task) + if err != nil { + this.ajaxMsg(err.Error(), MSG_ERR) + } + if jobs.AddJob(task.CronSpec, job) { + this.ajaxMsg("", MSG_OK) + } else { + this.ajaxMsg("编辑后刷新任务失败", MSG_ERR) + } + } this.ajaxMsg("", MSG_OK) }