zhangqian
2023-09-12 b555874608be2e4bb40cceba60b497c04caef842
crontask/cron_task.go
@@ -3,9 +3,11 @@
import (
   "apsClient/conf"
   "apsClient/constvar"
   "apsClient/nsq"
   "apsClient/pkg/ecode"
   "apsClient/pkg/logx"
   "apsClient/service"
   "fmt"
   "github.com/go-co-op/gocron"
   "github.com/spf13/cast"
   "time"
@@ -39,7 +41,7 @@
      return err
   }
   s.Every(totalNumberTimeInterval).Seconds().StartImmediately().Do(func() {
   s.Every(totalNumberTimeInterval).Seconds().Do(func() {
      plcConfig, code := service.NewDevicePlcService().GetDevicePlc()
      if code != ecode.OK {
         return
@@ -51,6 +53,23 @@
      logx.Infof("plc read total number:%v, err:%v", totalNumber, err)
   })
   s.Every(60).Seconds().StartImmediately().Do(SyncProductionProgress) //同步生产数据
   s.StartAsync()
   return nil
}
func SyncProductionProgress() {
   progress, err := service.NewProgressService().GetCurrentProgress()
   if err != nil {
      return
   }
   if progress == nil {
      return
   }
   caller := nsq.NewCaller(fmt.Sprintf(constvar.NsqTopicSyncTaskProgress, conf.Conf.NsqConf.NodeId), "")
   err = caller.Send(progress)
   if err != nil {
      logx.Errorf("SyncProductionProgress error:%v", err.Error())
   }
}