12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- 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)
- )
- func main() {
- m := flag.Int("m", 0, "模式 0:定时任务 1:非定时任务")
- t := flag.String("t", "", "表名")
- flag.Parse()
- all := []Entity{Raw_user, Raw_product, Action_order, Action_product_record}
- if *m == 1 {
- if *t == "raw_user" {
- run(Raw_user)
- } else if *t == "raw_product" {
- run(Raw_product)
- } else if *t == "action_order" || *t == "action_order_spec" {
- run(Action_order)
- } else if *t == "action_product_record" {
- run(Action_order, Action_product_record)
- } else if *t == "" {
- run(all...)
- }
- } 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("同步任务结束。。。")
- }
|