From 710c7c79d4cc613965dc5c3b5f3860959caaa6b1 Mon Sep 17 00:00:00 2001 From: albertma Date: Tue, 26 Apr 2016 18:11:49 +0800 Subject: [PATCH 1/3] 1.fix start task twice issue --- toolbox/task.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/toolbox/task.go b/toolbox/task.go index 537de428..f9492f8f 100644 --- a/toolbox/task.go +++ b/toolbox/task.go @@ -389,11 +389,16 @@ func dayMatches(s *Schedule, t time.Time) bool { // StartTask start all tasks func StartTask() { + if isstart { + //If already started, no need to start another goroutine. + return + } isstart = true go run() } func run() { + now := time.Now().Local() for _, t := range AdminTaskList { t.SetNext(now) @@ -417,7 +422,7 @@ func run() { if e.GetNext() != effective { break } - go e.Run() + go e.Run() e.SetPrev(e.GetNext()) e.SetNext(effective) } @@ -432,8 +437,11 @@ func run() { // StopTask stop all tasks func StopTask() { - isstart = false - stop <- true + if(isstart){ + isstart = false + stop <- true + } + } // AddTask add task with name From a271d67ba4d4401a550cce0d5ffdb126dd9c2820 Mon Sep 17 00:00:00 2001 From: albertma Date: Tue, 26 Apr 2016 18:13:52 +0800 Subject: [PATCH 2/3] 1.fix blank issue --- toolbox/task.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolbox/task.go b/toolbox/task.go index f9492f8f..90bd2a0d 100644 --- a/toolbox/task.go +++ b/toolbox/task.go @@ -422,7 +422,7 @@ func run() { if e.GetNext() != effective { break } - go e.Run() + go e.Run() e.SetPrev(e.GetNext()) e.SetNext(effective) } From e607be6fa62b1d3207166e870f20309c981b7122 Mon Sep 17 00:00:00 2001 From: albertma Date: Fri, 29 Apr 2016 10:28:10 +0800 Subject: [PATCH 3/3] gofmt the code --- toolbox/task.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/toolbox/task.go b/toolbox/task.go index 90bd2a0d..abd411c8 100644 --- a/toolbox/task.go +++ b/toolbox/task.go @@ -389,16 +389,15 @@ func dayMatches(s *Schedule, t time.Time) bool { // StartTask start all tasks func StartTask() { - if isstart { - //If already started, no need to start another goroutine. - return - } + if isstart { + //If already started, no need to start another goroutine. + return + } isstart = true go run() } func run() { - now := time.Now().Local() for _, t := range AdminTaskList { t.SetNext(now) @@ -422,7 +421,7 @@ func run() { if e.GetNext() != effective { break } - go e.Run() + go e.Run() e.SetPrev(e.GetNext()) e.SetNext(effective) } @@ -437,10 +436,10 @@ func run() { // StopTask stop all tasks func StopTask() { - if(isstart){ - isstart = false - stop <- true - } + if isstart { + isstart = false + stop <- true + } }