From 9e3412941ea49942f651506657d90ab174a4329f Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期二, 17 十月 2023 17:10:36 +0800 Subject: [PATCH] 工单开始或结束时保存待同步任务 --- crontask/cron_task.go | 34 +++++++++++++++++++++++++++++++--- 1 files changed, 31 insertions(+), 3 deletions(-) diff --git a/crontask/cron_task.go b/crontask/cron_task.go index 9454dbe..5668ea1 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,30 @@ 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