From f061c98454bf0931352023199251230e90f2e80b Mon Sep 17 00:00:00 2001 From: iwannay <772648576@qq.com> Date: Tue, 6 Aug 2019 09:19:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E7=A7=92=E5=86=85?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jiacrontabd/jiacrontabd.go | 18 ++++++++++++------ jiacrontabd/job.go | 16 +++------------- jiacrontabd/srv.go | 2 +- pkg/version/ver.go | 2 +- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/jiacrontabd/jiacrontabd.go b/jiacrontabd/jiacrontabd.go index 505947d2..07cc2604 100644 --- a/jiacrontabd/jiacrontabd.go +++ b/jiacrontabd/jiacrontabd.go @@ -69,7 +69,7 @@ func (j *Jiacrontabd) removeTmpJob(job *JobEntry) { j.mux.Unlock() } -func (j *Jiacrontabd) addJob(job *crontab.Job) { +func (j *Jiacrontabd) addJob(job *crontab.Job, updateLastExecTime bool) { j.mux.Lock() if v, ok := j.jobs[job.ID]; ok { v.job = job @@ -81,11 +81,17 @@ func (j *Jiacrontabd) addJob(job *crontab.Job) { if err := j.crontab.AddJob(job); err != nil { log.Error("NextExecutionTime:", err, " timeArgs:", job) } else { + data := map[string]interface{}{ + "next_exec_time": job.GetNextExecTime(), + "status": models.StatusJobTiming, + } + + if updateLastExecTime { + data["last_exec_time"] = time.Now() + } + if err := models.DB().Model(&models.CrontabJob{}).Where("id=?", job.ID). - Updates(map[string]interface{}{ - "next_exec_time": job.GetNextExecTime(), - "status": models.StatusJobTiming, - }).Error; err != nil { + Updates(data).Error; err != nil { log.Error(err) } } @@ -411,7 +417,7 @@ func (j *Jiacrontabd) recovery() { Day: v.TimeArgs.Day, Month: v.TimeArgs.Month, Weekday: v.TimeArgs.Weekday, - }) + }, false) } err = models.DB().Find(&daemonJobs, "status in (?)", []models.JobStatus{models.StatusJobOk}).Error diff --git a/jiacrontabd/job.go b/jiacrontabd/job.go index 0faad293..59730347 100644 --- a/jiacrontabd/job.go +++ b/jiacrontabd/job.go @@ -405,14 +405,14 @@ func (j *JobEntry) exec() { Day: j.detail.TimeArgs.Day, Month: j.detail.TimeArgs.Month, Weekday: j.detail.TimeArgs.Weekday, - }) + }, false) return } - j.jd.addJob(j.job) + j.jd.addJob(j.job, true) } if atomic.LoadInt32(&j.processNum) >= int32(j.detail.MaxConcurrent) && j.detail.MaxConcurrent != 0 { - j.logContent = []byte("不得超过job最大并发数量") + j.logContent = []byte("不得超过job最大并发数量\n") return } @@ -475,7 +475,6 @@ func (j *JobEntry) updateJob(status models.JobStatus, startTime, endTime time.Ti data := map[string]interface{}{ "status": status, "process_num": atomic.LoadInt32(&j.processNum), - "last_exec_time": j.job.GetLastExecTime(), "last_exit_status": "", "failed": false, } @@ -484,14 +483,6 @@ func (j *JobEntry) updateJob(status models.JobStatus, startTime, endTime time.Ti data["last_cost_time"] = endTime.Sub(startTime).Seconds() } - // if j.once && (status == models.StatusJobRunning) { - // data["process_num"] = gorm.Expr("process_num + ?", 1) - // } - - // if j.once && (status == models.StatusJobTiming) { - // data["process_num"] = gorm.Expr("process_num - ?", 1) - // } - var errMsg string if err != nil { errMsg = err.Error() @@ -500,7 +491,6 @@ func (j *JobEntry) updateJob(status models.JobStatus, startTime, endTime time.Ti } if j.once { - delete(data, "last_exec_time") delete(data, "status") delete(data, "last_exit_status") } diff --git a/jiacrontabd/srv.go b/jiacrontabd/srv.go index 2dd3d832..2f1c0ce3 100644 --- a/jiacrontabd/srv.go +++ b/jiacrontabd/srv.go @@ -157,7 +157,7 @@ func (j *CrontabJob) Start(args proto.ActionJobsArgs, jobs *[]models.CrontabJob) Day: v.TimeArgs.Day, Month: v.TimeArgs.Month, Weekday: v.TimeArgs.Weekday, - }) + }, false) } return nil diff --git a/pkg/version/ver.go b/pkg/version/ver.go index 6509a4da..39cfbef7 100644 --- a/pkg/version/ver.go +++ b/pkg/version/ver.go @@ -5,7 +5,7 @@ import ( "runtime" ) -const Binary = "2.0.1" +const Binary = "2.0.2" func String(app string) string { return fmt.Sprintf("%s v%s (built w/%s)", app, Binary, runtime.Version())