From f838162ed0ee7f2832924c2399eddd461760135a Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 13 十月 2023 21:47:54 +0800
Subject: [PATCH] plc地址和工艺参数不再单独拉取,只serf主启动时拉取

---
 crontask/cron_task.go |   33 ++++++++++++++++++++++++++++++---
 1 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/crontask/cron_task.go b/crontask/cron_task.go
index 9454dbe..e462c68 100644
--- a/crontask/cron_task.go
+++ b/crontask/cron_task.go
@@ -3,6 +3,7 @@
 import (
 	"apsClient/conf"
 	"apsClient/constvar"
+	"apsClient/model/common"
 	"apsClient/nsq"
 	"apsClient/pkg/ecode"
 	"apsClient/pkg/logx"
@@ -13,8 +14,9 @@
 	"time"
 )
 
-func InitTask() error {
+var s *gocron.Scheduler
 
+func StartTask() error {
 	finishNumberTimeInterval := conf.Conf.PLC.FinishNumberTimeInterval
 	totalNumberTimeInterval := conf.Conf.PLC.TotalNumberTimeInterval
 	if finishNumberTimeInterval == 0 {
@@ -23,7 +25,7 @@
 	if totalNumberTimeInterval == 0 {
 		totalNumberTimeInterval = 60
 	}
-	s := gocron.NewScheduler(time.UTC)
+	s = gocron.NewScheduler(time.UTC)
 	_, err := s.Every(finishNumberTimeInterval).Seconds().Do(func() {
 		plcConfig, code := service.NewDevicePlcService().GetDevicePlc()
 		if code != ecode.OK {
@@ -73,7 +75,8 @@
 
 	})
 
-	s.Every(180).Seconds().Do(SyncProductionProgress) //鍚屾鐢熶骇鏁版嵁
+	s.Every(60).Seconds().Do(SyncProductionProgress) //鍚屾鐢熶骇鏁版嵁
+	s.Every(60).Seconds().Do(SyncTaskStatus)         //鍚屾浠诲姟鐘舵��
 	s.StartAsync()
 	return nil
 }
@@ -104,5 +107,29 @@
 			logx.Errorf("SyncProductionProgress error:%v", err.Error())
 		}
 	}
+}
 
+func SyncTaskStatus() {
+	//todo
+}
+
+func StopTask() {
+	if s != nil {
+		s.Stop()
+	}
+}
+
+// Once 涓�娆℃�т换鍔�
+func Once() {
+	msg := &common.MsgPullDataRequest{DataType: common.PullDataTypeProcessModel}
+	caller := nsq.NewCaller(fmt.Sprintf(constvar.NsqTopicPullDataRequest, conf.Conf.NsqConf.NodeId), constvar.NsqTopicPullDataResponse)
+	err := caller.Send(msg)
+	if err != nil {
+		logx.Errorf("send pull data msg error:%v", err.Error())
+	}
+	caller = nsq.NewCaller(fmt.Sprintf(constvar.NsqTopicGetPlcAddress, conf.Conf.NsqConf.NodeId), "")
+	err = caller.Send(common.RequestPlcAddress{DeviceId: conf.Conf.System.DeviceId})
+	if err != nil {
+		logx.Infof("get plc address err: %v", err.Error())
+	}
 }

--
Gitblit v1.8.0