zhangzengfei
2023-08-14 8f750b461a4f442825e516016bf78d05ed66afcb
report/task.go
File was renamed from report/loop.go
@@ -11,18 +11,18 @@
var ctx context.Context
var cancel context.CancelFunc
func StartReport() {
func Start() {
   ctx, cancel = context.WithCancel(context.Background())
   go Loop(ctx)
   go queryTasks(ctx)
}
func RestartReport() {
   cancel()
   StartReport()
   Start()
}
func Loop(c context.Context) {
func queryTasks(c context.Context) {
   logger.Debug("启动数据上报任务")
   for {
      select {
@@ -31,15 +31,19 @@
         return
      default:
         // 上报订单
         SendOrder()
         if config.Options.OrderTopic != "" {
            SendOrder()
         }
         // 上报即时库存
         SendInventory()
         if config.Options.InventoryTopic != "" {
            SendInventory()
         }
         // 测试查询请求
         //sql := []byte("select * from t_icitem where FItemID=3316")
         //ok := nsqclient.Produce(config.Options.SqlQueryTopic, sql)
         //logger.Debug("测试请求接口, %v", ok)
         // 上报bom
         if config.Options.BomTopic != "" {
            SendBom(true)
         }
         time.Sleep(time.Duration(config.Options.SyncInterval) * time.Second)
      }