|
@@ -21,11 +21,14 @@ var (
|
|
|
cloudStatus = "NONE"
|
|
|
lastLocalStatus = "idle"
|
|
|
lastCloudStatus = "NONE"
|
|
|
+ localTurnLength = 1
|
|
|
+ cloudTurnLength = 60
|
|
|
+ renewTurnLength = 3
|
|
|
+ waitStopLength = 1
|
|
|
launchedFlag = false
|
|
|
renewedFlag = false
|
|
|
- configuredFlag = false
|
|
|
renewTimer *time.Timer
|
|
|
- RenewDur = 5
|
|
|
+ RenewDur = 5
|
|
|
)
|
|
|
|
|
|
func init() {
|
|
@@ -45,14 +48,20 @@ func init() {
|
|
|
}
|
|
|
|
|
|
func renew() {
|
|
|
- if renewTimer != nil {
|
|
|
- renewTimer.Stop()
|
|
|
+ for {
|
|
|
+ time.Sleep(time.Duration(renewTurnLength) * time.Second)
|
|
|
+ if localStatus == "running" && !renewedFlag {
|
|
|
+ c_log.GlobalLogger.Info("设备仍处于运行状态,续约 - 开始。")
|
|
|
+ if renewTimer != nil {
|
|
|
+ renewTimer.Stop()
|
|
|
+ }
|
|
|
+ renewedFlag = true
|
|
|
+ renewTimer = time.AfterFunc(time.Duration(RenewDur)*time.Minute, func() {
|
|
|
+ renewedFlag = false
|
|
|
+ })
|
|
|
+ c_log.GlobalLogger.Infof("续约时间【%v】分钟 - 成功。", RenewDur)
|
|
|
+ }
|
|
|
}
|
|
|
- renewedFlag = true
|
|
|
- renewTimer = time.AfterFunc(time.Duration(RenewDur)*time.Minute, func() {
|
|
|
- renewedFlag = false
|
|
|
- })
|
|
|
- c_log.GlobalLogger.Infof("续约时间【%v】分钟 - 成功。", RenewDur)
|
|
|
}
|
|
|
|
|
|
func startMasterNode() {
|
|
@@ -85,9 +94,6 @@ func stopMasterNode() {
|
|
|
reply := 0
|
|
|
if err = KillRpcClient.Call("KillService.Kill", killArgs, &reply); err != nil {
|
|
|
c_log.GlobalLogger.Error("发送 rpc 请求到 master 报错:", err)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
c_log.GlobalLogger.Info("结束任务后,将数据闭环平台配置置空。")
|
|
@@ -101,10 +107,6 @@ func stopMasterNode() {
|
|
|
}
|
|
|
|
|
|
func main() {
|
|
|
- localTurnLength := 2
|
|
|
- cloudTurnLength := 60
|
|
|
- waitStopLength := 1
|
|
|
-
|
|
|
|
|
|
go pkg.GetLocalStatus(&localStatus, &lastLocalStatus, localTurnLength)
|
|
|
|
|
@@ -135,19 +137,13 @@ func main() {
|
|
|
if !launchedFlag {
|
|
|
c_log.GlobalLogger.Info("数采程序启动 - 开始。")
|
|
|
startMasterNode()
|
|
|
- } else {
|
|
|
- c_log.GlobalLogger.Info("设备仍处于运行状态,续约 - 开始。")
|
|
|
-
|
|
|
- renew()
|
|
|
}
|
|
|
- continue
|
|
|
} else if localStatus == "idle" {
|
|
|
if !renewedFlag && launchedFlag && len(entity.TimeWindowConsumerQueue) == 0 {
|
|
|
- c_log.GlobalLogger.Info("设备不在运行状态且没有待处理的数据,数采程序关闭 - 开始。")
|
|
|
time.Sleep(time.Duration(waitStopLength) * time.Minute)
|
|
|
+ c_log.GlobalLogger.Info("设备不在运行状态且没有待处理的数据,数采程序关闭 - 开始。")
|
|
|
stopMasterNode()
|
|
|
}
|
|
|
- continue
|
|
|
} else if localStatus == "error" {
|
|
|
c_log.GlobalLogger.Error("设备运行状态出错,停止数采程序。")
|
|
|
stopMasterNode()
|
|
@@ -155,66 +151,12 @@ func main() {
|
|
|
c_log.GlobalLogger.Error("未知的设备运行状态。【status】=", localStatus)
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ go renew()
|
|
|
+
|
|
|
|
|
|
go pkg.GetCloudConfig(cloudStatus, lastCloudStatus, cloudTurnLength)
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|