package services import ( "context" "fmt" "github.com/beego/beego/v2/task" "hongze/hongze_task_trial/services/data" "hongze/hongze_task_trial/utils" "sync" "time" ) func Task() { fmt.Println("task start") //如果是生产环境,才需要走这些任务 if utils.RunMode == "release" { releaseTask() } task.StartTask() fmt.Println("task end") } // 生产环境需要走的任务 func releaseTask() { //同步指标 syncHzDataIndex := task.NewTask("syncHzDataIndex", "0 30 18 * * *", SyncHzDataIndex) task.AddTask("syncHzDataIndex", syncHzDataIndex) //刷新指标数据 refreshData := task.NewTask("refreshData", "0 30 0,19 * * *", RefreshData) task.AddTask("refreshData", refreshData) syncBaseDataExt := task.NewTask("syncBaseDataExt", "0 */30 * * * * ", SyncBaseDataExt) task.AddTask("syncBaseDataExt", syncBaseDataExt) //初始化指标更新状态 resetEdbInfoIsUpdate := task.NewTask("resetEdbInfoIsUpdate", "0 0 0 * * *", data.ResetEdbInfoIsUpdate) task.AddTask("resetEdbInfoIsUpdate", resetEdbInfoIsUpdate) } func RefreshData(cont context.Context) (err error) { fmt.Println("Refresh Start") wg := sync.WaitGroup{} wg.Add(6) //同花顺 go data.RefreshDataFromThs(&wg) //彭博 go data.RefreshDataFromPb(&wg) //彭博财务 go data.RefreshDataFromPbFinance(&wg) //手工数据 go data.RefreshDataFromManual(&wg) //谷歌出行数据 go data.RefreshDataFromGoogleTravel(&wg) //eia steo报告指标 go data.RefreshDataFromEiaSteo(&wg) wg.Wait() //计算指标 data.RefreshDataFromCalculateAll() // 预测计算指标 data.RefreshPredictDataFromCalculateAll() //time.Sleep(5 * time.Second) // //// 刷新商品期货数据 //{ // future_good.RefreshFutureGoodDataFromThs() //} fmt.Println("Refresh End") return } // 刷新基础数据 func SyncBaseDataExt(cont context.Context) (err error) { now := time.Now() if now.Hour() == 0 || now.Hour() == 19 { return nil } //同步手工数据 go data.SyncManualDataBase() //刷新图表中,指标的最新日期 go data.SetChartEdbEndDate() return }