mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 14:40:57 +00:00
1.fix start task twice issue
This commit is contained in:
parent
88c5dfa6ea
commit
710c7c79d4
@ -389,11 +389,16 @@ func dayMatches(s *Schedule, t time.Time) bool {
|
|||||||
|
|
||||||
// StartTask start all tasks
|
// StartTask start all tasks
|
||||||
func StartTask() {
|
func StartTask() {
|
||||||
|
if isstart {
|
||||||
|
//If already started, no need to start another goroutine.
|
||||||
|
return
|
||||||
|
}
|
||||||
isstart = true
|
isstart = true
|
||||||
go run()
|
go run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func run() {
|
func run() {
|
||||||
|
|
||||||
now := time.Now().Local()
|
now := time.Now().Local()
|
||||||
for _, t := range AdminTaskList {
|
for _, t := range AdminTaskList {
|
||||||
t.SetNext(now)
|
t.SetNext(now)
|
||||||
@ -417,7 +422,7 @@ func run() {
|
|||||||
if e.GetNext() != effective {
|
if e.GetNext() != effective {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
go e.Run()
|
go e.Run()
|
||||||
e.SetPrev(e.GetNext())
|
e.SetPrev(e.GetNext())
|
||||||
e.SetNext(effective)
|
e.SetNext(effective)
|
||||||
}
|
}
|
||||||
@ -432,8 +437,11 @@ func run() {
|
|||||||
|
|
||||||
// StopTask stop all tasks
|
// StopTask stop all tasks
|
||||||
func StopTask() {
|
func StopTask() {
|
||||||
isstart = false
|
if(isstart){
|
||||||
stop <- true
|
isstart = false
|
||||||
|
stop <- true
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddTask add task with name
|
// AddTask add task with name
|
||||||
|
Loading…
Reference in New Issue
Block a user