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) ly.RunLyTask(lyRemain, ConfigDir)
lxmain.RunMainTask(mainRemain, ConfigDir) lxmain.RunMainTask(mainRemain, ConfigDir)
mip.RunMipTask(mipRemain, ConfigDir) mip.RunMipTask(mipRemain, ConfigDir)
// 根据cron表达式进行时间调度,cron可以精确到秒 //// 根据cron表达式进行时间调度,cron可以精确到秒
//crontab := cron.New() 默认从分开始进行时间调度 ////crontab := cron.New() 默认从分开始进行时间调度
crontab := cron.New(cron.WithSeconds()) //精确到秒 //crontab := cron.New(cron.WithSeconds()) //精确到秒
//定义定时器调用的任务函数 ////定义定时器调用的任务函数
task := func() { //task := func() {
logger.Info("定时任务启动,每天凌晨1点运行") // 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() // defer db.SeoDB.Close()
defer db.SpuDB.Close() // defer db.SpuDB.Close()
defer db.GoodsDB.Close() // defer db.GoodsDB.Close()
defer db.SkuDB.Close() // defer db.SkuDB.Close()
defer db.LxDB.Close() // defer db.LxDB.Close()
////fmt.Println("******** ******* *******") // ////fmt.Println("******** ******* *******")
//fmt.Println("Time now:", time.Now().Format("2006-01-02 15:04:05")) // //fmt.Println("Time now:", time.Now().Format("2006-01-02 15:04:05"))
} //}
//定时任务 ////定时任务
spec := "0 0 1 * * ?" //cron表达式,每天凌晨1点运行 //spec := "0 0 1 * * ?" //cron表达式,每天凌晨1点运行
//spec := "2 * * * * *" //cron表达式,表示每分钟的第2s执行一次 ////spec := "2 * * * * *" //cron表达式,表示每分钟的第2s执行一次
// 添加定时任务, //// 添加定时任务,
_, _ = crontab.AddFunc(spec, task) //_, _ = crontab.AddFunc(spec, task)
// 启动定时器 //// 启动定时器
crontab.Start() //crontab.Start()
//阻塞主线程停止 ////阻塞主线程停止
select {} //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