1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package main
- import (
- "flag"
- "fmt"
- "log"
- . "online_datasync/config"
- . "online_datasync/entity"
- "sync"
- "time"
- . "app.yhyue.com/moapp/jybase/common"
- . "app.yhyue.com/moapp/jybase/date"
- )
- var (
- wait = &sync.WaitGroup{}
- pool = make(chan bool, Config.SyncPool)
- allMap = map[string]Entity{
- "raw_user": Raw_user,
- "bxt_raw_user": Bxt_raw_user,
- //"raw_product": Raw_product,
- //"action_order": Action_order,
- //"action_order_spec": Action_order,
- //"action_product_record": Action_product_record,
- //"user_prize": User_prize,
- "integral_flow": Integral_flow,
- //"point_type": Point_type,
- }
- )
- func main() {
- m := flag.Int("m", 0, "模式 0:定时任务 1:非定时任务")
- t := flag.String("t", "", "表名")
- flag.Parse()
- all := []Entity{}
- for _, v := range allMap {
- all = append(all, v)
- }
- if *m == 1 {
- if *t == "" {
- run(all...)
- } else if allMap[*t] != nil {
- run(allMap[*t])
- } else {
- log.Fatalln(*t, "表的同步数据任务不存在")
- }
- } else {
- SimpleCrontab(false, Config.RunTime, func() {
- run(all...)
- })
- select {}
- }
- }
- //
- func run(es ...Entity) {
- now := time.Now()
- //
- var start_unix int64
- if TimeTask.Datetime != "" {
- start, err := time.ParseInLocation(Date_Full_Layout, TimeTask.Datetime, time.Local)
- if err != nil {
- log.Fatalln(err)
- }
- start_unix = start.Unix()
- }
- //
- end_unix := now.Unix()
- end_layout := FormatDate(&now, Date_Full_Layout)
- log.Println("同步任务开始。。。", fmt.Sprintf("%+v", TimeTask))
- //
- for _, e := range es {
- pool <- true
- wait.Add(1)
- go func(v Entity) {
- defer func() {
- <-pool
- wait.Done()
- }()
- v.Run(start_unix, end_unix, TimeTask.Datetime, end_layout)
- }(e)
- }
- //
- wait.Wait()
- TimeTask.Datetime = end_layout
- WriteSysConfig("./timetask.json", &TimeTask)
- log.Println("同步任务结束。。。")
- }
|