Golang Cron定时任务

96
莫夏_b560
2019.01.11 14:15* 字数 40

Cron定时任务

go get -u github.com/robfig/cron

备注:http://www.pppet.net/:cron生成,如果跟我一样对cron格式迷惑的朋友可以手动设置下

package main

import (
    "log"

    "github.com/robfig/cron"
)

func main() {
    log.Println("Starting...")

    c := cron.New()
    c.AddFunc("* * * * * *", func() {
        log.Println("Run models.CleanAllTag...")
    })
    c.AddFunc("* * * * * *", func() {
        log.Println("Run models.CleanAllArticle...")
    })

    c.Start()

    //t1 := time.NewTimer(time.Second * 10)
    //for {
    //  select {
    //  case <-t1.C:
    //      t1.Reset(time.Second * 10)
    //  }
    //}
    select {
    
    }
}
GO
Web note ad 1