go get github.com/stupboy/corn
- [* * * * * * 秒 分 时 日 周 月]
- [* * * * * * 为每秒执行一次]
- [01 00 12 * * * 为秒为12时00分01秒时执行]
- [1-5 * * * * * 为秒为1-5时,每次都执行]
- [1,3,5 * * * * * 秒为 1 3 5时执行]
- [*/5 * * * * * 为每5秒执行一次]
package main
import (
"github.com/stupboy/corn"
"log"
)
func init(){
cornTask := corn.New()
cornTask.AddCorn(test,"*/5 * * * * *","test")
cornTask.AddCorn(test1,"*/2 * * * * *","test1")
//cornTask.RunCorn(500)
cornTask.RunCorn()
}
func test(){
log.Println("aa")
}
func test1(){
log.Println("bb")
}
func main(){
select {}
}
cornTask.AddIgnore("test")//增加定时任务限制
cornTask.DelIgnore("teset")//取消定时任务限制