Commit fa223cd0 by lzzzzl

修改定时

parent aa1a834f
Showing with 28 additions and 28 deletions
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"github.com/ichunt2019/golang-rbmq-sl/utils/rabbitmq" "github.com/ichunt2019/golang-rbmq-sl/utils/rabbitmq"
"github.com/ichunt2019/logger" "github.com/ichunt2019/logger"
"github.com/robfig/cron/v3"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"golang-seo-server/collect/lxmain" "golang-seo-server/collect/lxmain"
"golang-seo-server/collect/ly" "golang-seo-server/collect/ly"
...@@ -104,35 +103,36 @@ func main() { ...@@ -104,35 +103,36 @@ func main() {
fmt.Println(lyRemain) fmt.Println(lyRemain)
fmt.Println(mainRemain) fmt.Println(mainRemain)
fmt.Println(mipRemain) fmt.Println(mipRemain)
ly.RunLyTask(lyRemain, ConfigDir)
lxmain.RunMainTask(mainRemain, ConfigDir)
mip.RunMipTask(mipRemain, ConfigDir)
// 根据cron表达式进行时间调度,cron可以精确到秒
//crontab := cron.New() 默认从分开始进行时间调度
crontab := cron.New(cron.WithSeconds()) //精确到秒
//定义定时器调用的任务函数
task := func() {
logger.Info("定时任务启动,每天凌晨1点运行")
ly.RunLyTask(lyRemain, ConfigDir) ly.RunLyTask(lyRemain, ConfigDir)
lxmain.RunMainTask(mainRemain, ConfigDir) lxmain.RunMainTask(mainRemain, ConfigDir)
mip.RunMipTask(mipRemain, ConfigDir) mip.RunMipTask(mipRemain, ConfigDir)
//
defer db.SeoDB.Close() //// 根据cron表达式进行时间调度,cron可以精确到秒
defer db.SpuDB.Close() ////crontab := cron.New() 默认从分开始进行时间调度
defer db.GoodsDB.Close() //crontab := cron.New(cron.WithSeconds()) //精确到秒
defer db.SkuDB.Close() ////定义定时器调用的任务函数
defer db.LxDB.Close() //task := func() {
////fmt.Println("******** ******* *******") // logger.Info("定时任务启动,每天凌晨1点运行")
//fmt.Println("Time now:", time.Now().Format("2006-01-02 15:04:05")) // ly.RunLyTask(lyRemain, ConfigDir)
} // lxmain.RunMainTask(mainRemain, ConfigDir)
//定时任务 // mip.RunMipTask(mipRemain, ConfigDir)
spec := "0 0 1 * * ?" //cron表达式,每天凌晨1点运行 // //
//spec := "2 * * * * *" //cron表达式,表示每分钟的第2s执行一次 // defer db.SeoDB.Close()
// 添加定时任务, // defer db.SpuDB.Close()
_, _ = crontab.AddFunc(spec, task) // defer db.GoodsDB.Close()
// 启动定时器 // defer db.SkuDB.Close()
crontab.Start() // defer db.LxDB.Close()
//阻塞主线程停止 // ////fmt.Println("******** ******* *******")
select {} // //fmt.Println("Time now:", time.Now().Format("2006-01-02 15:04:05"))
//}
////定时任务
//spec := "0 0 1 * * ?" //cron表达式,每天凌晨1点运行
////spec := "2 * * * * *" //cron表达式,表示每分钟的第2s执行一次
//// 添加定时任务,
//_, _ = crontab.AddFunc(spec, task)
//// 启动定时器
//crontab.Start()
////阻塞主线程停止
//select {}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment