支持多台服务器同时执行任务+优化页面

一个定时任务可以允许多台服务器同时执行任务,优化页面关闭并刷新列表页
This commit is contained in:
georgehao
2019-04-16 23:40:07 +08:00
parent 07aff7ee72
commit 830d49ee1c
24 changed files with 391 additions and 137 deletions

View File

@@ -32,7 +32,7 @@ func AddJob(spec string, job *Job) bool {
lock.Lock()
defer lock.Unlock()
if GetEntryById(job.id) != nil {
if GetEntryById(job.jobKey) != nil {
return false
}
err := mainCron.AddJob(spec, job)
@@ -40,13 +40,14 @@ func AddJob(spec string, job *Job) bool {
beego.Error("AddJob: ", err.Error())
return false
}
//fmt.Println(job)
return true
}
func RemoveJob(id int) {
func RemoveJob(jobKey int) {
mainCron.RemoveJob(func(e *cron.Entry) bool {
if v, ok := e.Job.(*Job); ok {
if v.id == id {
if v.jobKey == jobKey {
return true
}
}
@@ -54,11 +55,11 @@ func RemoveJob(id int) {
})
}
func GetEntryById(id int) *cron.Entry {
func GetEntryById(jobKey int) *cron.Entry {
entries := mainCron.Entries()
for _, e := range entries {
if v, ok := e.Job.(*Job); ok {
if v.id == id {
if v.jobKey == jobKey {
return e
}
}