Beego|Beego 定时任务

main.go

package main import ( "github.com/astaxie/beego" "github.com/astaxie/beego/toolbox" "traceability_management/utils" )func main() { // 定时任务 utils.InitTask() toolbox.StartTask() defer toolbox.StopTask()beego.Run() }

Task.go
package utilsimport ( "github.com/astaxie/beego/orm" "github.com/astaxie/beego/toolbox" "time" "traceability_management/models" )func InitTask(){ tk := toolbox.NewTask("generateWarning", "0 0 0 * * *", GenerateWarning) //err := tk.Run() //if err != nil { //fmt.Println(err) //} toolbox.AddTask("generateWarning",tk) }func GenerateWarning() error { // 业务 return err }

    推荐阅读