beego 定时任务

package main

import (
    "fmt"
    "github.com/astaxie/beego/toolbox"
    "time"
)

func task() error {
    fmt.Println(time.Now().Format("2006-01-02 15:04:05"))
    return nil
}

func main() {
    tk := toolbox.NewTask("task1", "0/5 * * * * 5", task)
    err := tk.Run()
    if err != nil{
        fmt.Println(err)
    }
    toolbox.AddTask("task1", tk)
    toolbox.StartTask()
    time.Sleep(time.Minute * 5)
    toolbox.StopTask()

}

 

posted @ 2020-03-20 10:11  眼镜儿  阅读(1648)  评论(0编辑  收藏  举报