|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- package task
-
- import (
- "applet/app/db"
- taskMd "applet/app/task/md"
- "applet/app/utils/logx"
- "github.com/robfig/cron/v3"
- "time"
- )
-
- var (
- timer *cron.Cron
- jobs = map[string]func(){}
- baseEntryId cron.EntryID
- entryIds []cron.EntryID
- ch = make(chan int, 30)
- workerNum = 15 // 智盟跟单并发数量
- )
-
- func Init() {
- // 初始化任务列表
- initTasks()
- var err error
- timer = cron.New()
- // reload为初始化数据库方法
- if baseEntryId, err = timer.AddFunc("@every 15m", reload); err != nil {
- _ = logx.Fatal(err)
- }
- }
-
- func Run() {
- reload()
- timer.Start()
- _ = logx.Info("auto tasks running...")
- }
-
- func reload() {
- // 重新初始化数据库
- sysCfgDb := db.SysCfgDb{}
- sysCfgDb.Set()
- cronList, _ := sysCfgDb.SysCfgGetCron()
-
- if cronList != nil {
- // 删除原有所有任务
- if len(entryIds) > 0 {
- for _, v := range entryIds {
- if v != baseEntryId {
- timer.Remove(v)
- }
- }
- entryIds = nil
- }
- var (
- entryId cron.EntryID
- err error
- )
- for _, vv := range *cronList {
- if _, ok := jobs[vv.K]; ok && vv.V != "" {
- // fmt.Println(vv.Val)
- if entryId, err = timer.AddFunc(vv.V, doTask(vv.K)); err == nil {
- entryIds = append(entryIds, entryId)
- }
- }
- }
-
- }
- }
-
- func doTask(fnName string) func() {
- return func() {
- begin := time.Now().Local()
- jobs[fnName]()
- end := time.Now().Local()
- logx.Infof(
- " AutoTask <%s> started at <%s>, ended at <%s> duration <%s>",
- fnName,
- begin.Format("2006-01-02 15:04:05.000"),
- end.Format("2006-01-02 15:04:05.000"),
- time.Duration(end.UnixNano()-begin.UnixNano()).String(),
- )
- }
- }
-
- // 增加自动任务队列
- func initTasks() {
- jobs[taskMd.ZhimengCronTikTokLocalLifeOrderSettle] = taskTikTokLocalLifeOrderSettle //c
- jobs[taskMd.ZhimengCronChanxuanOrderSettle] = taskChanxuanOrderSettle //c
- jobs[taskMd.ZhimengCronPLayletBihaiOrder] = taskPlayletBihaiOrder //
-
- jobs[taskMd.ZhimengCronCinema5bmsOrder] = taskCinema5bmsOrder //
- jobs[taskMd.ZhimengCronCinema5bmsYesterOrder] = taskCinema5bmsYesterOrder //
-
- jobs[taskMd.ZhimengCronTikTokCsjp] = taskTikTokCsjp //
- jobs[taskMd.ZhimengCronTikTokCsjpActivity] = taskTikTokCsjpActivity //
- jobs[taskMd.ZhimengCronTikTokCsjpLive] = taskTikTokCsjpLive //
- jobs[taskMd.ZhimengCronTikTokChanxuan] = taskTikTokCsjpChanxuan //
-
- jobs[taskMd.ZhimengCronTikTokTask] = taskTikTokTask //
- jobs[taskMd.ZhimengCronTikTokTaskRelate] = taskTikTokTaskRelate //
- jobs[taskMd.ZhimengCronTikTokTaskMoney] = taskTikTokTaskMoney //
- jobs[taskMd.ZhimengCronTikTokTaskMoneyByYestday] = taskTikTokTaskMoneyByYestday //
- jobs[taskMd.ZhimengCronDianzhongKuaishouMoney] = taskDianzhongKuaishouMoney //
- jobs[taskMd.ZhimengCronPlayletOrderSettle] = taskPlayletOrderSettle //
- jobs[taskMd.ZhimengCronHwOrderSettle] = taskHwOrderSettle //
- jobs[taskMd.ZhimengCronMasterMonthSettle] = taskMasterMonthSettle //
- jobs[taskMd.ZhimengCronHwStarbucksOrder] = taskHwStarbucksOrder //
- jobs[taskMd.ZhimengCronHwMovieOrder] = taskHwMovieOrder //
- jobs[taskMd.ZhimengCronHwMcdonaldOrder] = taskHwMcdonaldOrder //
- jobs[taskMd.ZhimengCronHwNayukiOrder] = taskHwNayukiOrder //
- jobs[taskMd.ZhimengCronHwLuckinOrder] = taskHwLuckinOrder //
- jobs[taskMd.ZhimengCronHwPizzaOrder] = taskHwPizzaOrder //
- jobs[taskMd.ZhimengCronHwPagodaOrder] = taskHwPagodaOrder //
- jobs[taskMd.ZhimengCronHwBurgerKingOrder] = taskHwBurgerKingOrder //
- jobs[taskMd.ZhimengCronHwHeyteaOrder] = taskHwHeyteaOrder //
- jobs[taskMd.ZhimengCronHwToKfcOrder] = taskHwToKfcOrder //
- jobs[taskMd.ZhimengCronHwWallaceOrder] = taskHwWallaceOrder //
- jobs[taskMd.ZhimengCronHwFlowerCakeOrder] = taskHwFlowerCakeOrder //
- jobs[taskMd.ZhimengCronHwDeliveryOrder] = taskHwDeliveryOrder //
- jobs[taskMd.ZhimengCronHwTourismOrder] = taskHwTourismOrder //
- jobs[taskMd.ZhimengCronTikTokLocalLifeOrder] = taskTikTokLocalLifeOrder //
- jobs[taskMd.ZhimengCronCsjpLocalLifeOrder] = taskCsjpLocalLifeOrder //
-
- jobs[taskMd.ZhimengCronKuaishouOrder] = taskKuaishouOrder //
- jobs[taskMd.ZhimengCronKuaishouAuth] = taskKuaishouAuth //
- jobs[taskMd.ZhimengCronMeituanOrder] = taskMeituanOrder //
- jobs[taskMd.ZhimengCronMeituanStoreOrder] = taskMeituanStoreOrder //
- jobs[taskMd.ZhimengCronLifeOrderSettle] = taskLifeOrderSettle //
-
- jobs[taskMd.ZhimengCronElmOrder] = taskElmOrder //
- jobs[taskMd.ZhimengCronDidiOrder] = taskDidiOrder //
- jobs[taskMd.ZhimengCronT3Order] = taskT3Order //
-
- }
|