task.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package services
  2. import (
  3. "context"
  4. "eta_gn/eta_task/services/data"
  5. "eta_gn/eta_task/services/data_stat"
  6. "eta_gn/eta_task/utils"
  7. "fmt"
  8. "sync"
  9. "time"
  10. "github.com/beego/beego/v2/task"
  11. )
  12. func Task() {
  13. fmt.Println("task start")
  14. // 如果开启了需要走生产环境的配置,才需要走这些任务
  15. if utils.RunMode == "release" || utils.IsStartReleaseTask {
  16. releaseTask()
  17. }
  18. //var ctx context.Context
  19. //_ = ReportWriteRemind(ctx)
  20. // 定时发布研报(国能没定时发布了)
  21. //publishReport := task.NewTask("publishReport", "0 */1 * * * *", PublishReport)
  22. //task.AddTask("定时发布研报", publishReport)
  23. // 定时汇总数据源终端指标更新情况
  24. setEdbSourceStatTask := task.NewTask("setEdbSourceStatTask", "0 20 19,23 * * *", data_stat.SetEdbSourceStatTask)
  25. task.AddTask("数据源统计表", setEdbSourceStatTask)
  26. GnTask()
  27. task.StartTask()
  28. fmt.Println("task end")
  29. }
  30. // 生产环境需要走的任务
  31. func releaseTask() {
  32. // 定时统计交易所的持仓分析数据
  33. //initPositionTask := task.NewTask("initPositionTask", "0 20,40 16-19 * * *", data.InitPositionTask)
  34. //task.AddTask("initPositionTask", initPositionTask)
  35. //刷新指标数据
  36. refreshData := task.NewTask("refreshData", "0 0 8,22 * * *", RefreshData)
  37. task.AddTask("refreshData", refreshData)
  38. // 根据配置刷新指标数据
  39. configRefreshData := task.NewTask("syncBaseDataExt", "0 */30 * * * * ", ConfigRefreshDataGn)
  40. task.AddTask("configRefreshData", configRefreshData)
  41. syncBaseDataExt := task.NewTask("syncBaseDataExt", "0 */30 * * * * ", SyncBaseDataExt)
  42. task.AddTask("syncBaseDataExt", syncBaseDataExt)
  43. //初始化指标更新状态
  44. resetEdbInfoIsUpdate := task.NewTask("resetEdbInfoIsUpdate", "0 0 0 * * *", data.ResetEdbInfoIsUpdate)
  45. task.AddTask("resetEdbInfoIsUpdate", resetEdbInfoIsUpdate)
  46. //删除日志 report_save_log,ppt_v2_save_log,保留一个月的
  47. deleteLog := task.NewTask("syncSubStatus", "0 0 2 2 * *", DeleteLog)
  48. task.AddTask("deleteLog", deleteLog)
  49. // 定时发布英文研报
  50. publishEnglishReport := task.NewTask("publishEnglishReport", "0 */1 * * * *", PublishEnglishReport)
  51. task.AddTask("定时发布英文研报", publishEnglishReport)
  52. // 每天清理两周前的报告保存日志
  53. clearReportSaveLog := task.NewTask("clearReportSaveLog", "0 15 23 * * *", ClearReportSaveLog)
  54. task.AddTask("定时清理报告保存日志", clearReportSaveLog)
  55. // 每天清理三个月前的用户操作日志
  56. clearAdminOperateLog := task.NewTask("clearAdminOperateLog", "0 20 23 * * *", ClearAdminOperateLog)
  57. task.AddTask("定时清理用户操作日志", clearAdminOperateLog)
  58. }
  59. func RefreshData(cont context.Context) (err error) {
  60. wg := sync.WaitGroup{}
  61. //手工数据
  62. go func() {
  63. wg.Add(1)
  64. data.RefreshDataFromManual(&wg)
  65. }()
  66. // 持仓分析
  67. //go func() {
  68. // wg.Add(1)
  69. // _ = data.RefreshDataFromTradeAnalysis(&wg)
  70. //}()
  71. // 刷新未配置刷新时间点的来源(可能含未知的来源, 统一在这个时间刷新)
  72. go func() {
  73. wg.Add(1)
  74. data.NoneConfigRefreshDataGn(&wg)
  75. }()
  76. wg.Wait()
  77. ////计算指标
  78. data.RefreshDataFromCalculateAll()
  79. // 刷新所有的基础预测指标
  80. data.RefreshBasePredictDataAll()
  81. // 预测计算指标
  82. data.RefreshPredictDataFromCalculateAll()
  83. // 指标系列计算数据
  84. _ = data.RefreshFactorEdbCalculateData()
  85. // 指标系列图表计算数据
  86. _ = data.RefreshFactorEdbChartCalculateData()
  87. time.Sleep(5 * time.Second)
  88. //data.RefreshNotice()
  89. fmt.Println("Refresh End")
  90. return
  91. }
  92. // SyncBaseDataExt 刷新基础数据
  93. func SyncBaseDataExt(cont context.Context) (err error) {
  94. now := time.Now()
  95. if now.Hour() == 0 || now.Hour() == 19 {
  96. return nil
  97. }
  98. //同步手工数据
  99. go data.SyncManualDataBase()
  100. //刷新图表中,指标的最新日期
  101. go data.SetChartEdbEndDate()
  102. return
  103. }