03eb1fc1 by astaxie

toolbox: add notify when add & delete task

1 parent 0a967875
...@@ -33,6 +33,7 @@ type bounds struct { ...@@ -33,6 +33,7 @@ type bounds struct {
33 var ( 33 var (
34 AdminTaskList map[string]Tasker 34 AdminTaskList map[string]Tasker
35 stop chan bool 35 stop chan bool
36 changed chan bool
36 seconds = bounds{0, 59, nil} 37 seconds = bounds{0, 59, nil}
37 minutes = bounds{0, 59, nil} 38 minutes = bounds{0, 59, nil}
38 hours = bounds{0, 23, nil} 39 hours = bounds{0, 23, nil}
...@@ -411,6 +412,8 @@ func run() { ...@@ -411,6 +412,8 @@ func run() {
411 e.SetNext(effective) 412 e.SetNext(effective)
412 } 413 }
413 continue 414 continue
415 case <-changed:
416 continue
414 case <-stop: 417 case <-stop:
415 return 418 return
416 } 419 }
...@@ -425,6 +428,13 @@ func StopTask() { ...@@ -425,6 +428,13 @@ func StopTask() {
425 // add task with name 428 // add task with name
426 func AddTask(taskname string, t Tasker) { 429 func AddTask(taskname string, t Tasker) {
427 AdminTaskList[taskname] = t 430 AdminTaskList[taskname] = t
431 changed <- true
432 }
433
434 // add task with name
435 func DeleteTask(taskname string) {
436 delete(AdminTaskList, taskname)
437 changed <- true
428 } 438 }
429 439
430 // sort map for tasker 440 // sort map for tasker
...@@ -578,4 +588,5 @@ func all(r bounds) uint64 { ...@@ -578,4 +588,5 @@ func all(r bounds) uint64 {
578 func init() { 588 func init() {
579 AdminTaskList = make(map[string]Tasker) 589 AdminTaskList = make(map[string]Tasker)
580 stop = make(chan bool) 590 stop = make(chan bool)
591 changed = make(chan bool)
581 } 592 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!