|
@@ -5,11 +5,9 @@ import (
|
|
|
commonService "cicv-data-closedloop/aarch64/jili/common/service"
|
|
|
"cicv-data-closedloop/common/config/c_log"
|
|
|
"cicv-data-closedloop/common/util"
|
|
|
- "fmt"
|
|
|
"net/rpc"
|
|
|
"os"
|
|
|
"runtime"
|
|
|
- "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -23,6 +21,8 @@ func init() {
|
|
|
commonConfig.InitOssConfig()
|
|
|
|
|
|
commonConfig.InitCloudConfig()
|
|
|
+
|
|
|
+ commonConfig.InitPlatformConfig()
|
|
|
}
|
|
|
|
|
|
func main() {
|
|
@@ -43,66 +43,50 @@ func RunWithInternet() {
|
|
|
wait = true
|
|
|
|
|
|
|
|
|
- platformTasks, err := commonConfig.GetConfig()
|
|
|
- fmt.Println("platformTasks", platformTasks)
|
|
|
- commonConfig.PlatformTasks = platformTasks
|
|
|
+ task, err := commonConfig.GetConfig()
|
|
|
if err != nil {
|
|
|
- c_log.GlobalLogger.Error("获取平台任务失败:", err)
|
|
|
+ c_log.GlobalLogger.Error("获取今日任务信息失败:", err)
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- for _, task := range platformTasks {
|
|
|
- flag := shouldExecuteTask(task.StartTime, task.EndTime)
|
|
|
- fmt.Println("flag", flag)
|
|
|
-
|
|
|
- if !flag {
|
|
|
+
|
|
|
+
|
|
|
+ if commonConfig.CurrTask.TaskConfigId == task.TaskConfigId {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if commonConfig.CurrTask.TaskConfigId != "" {
|
|
|
+ c_log.GlobalLogger.Info("需要执行的任务id为", task.TaskConfigId, ", 当前任务id为:", commonConfig.CurrTask.TaskConfigId, ", 需要杀死该任务。")
|
|
|
+
|
|
|
+ var killArgs commonService.KillSignal
|
|
|
+
|
|
|
+ killArgs = commonService.KillSignal{DropUploadData: true, Restart: false}
|
|
|
+ c_log.GlobalLogger.Info("杀死任务,发送rpc结束信号到本地:", killArgs)
|
|
|
+ KillRpcClient, err := rpc.Dial("tcp", commonConfig.LocalConfig.Node.Ip+":"+commonConfig.CloudConfig.RpcPort)
|
|
|
+ if err != nil {
|
|
|
+
|
|
|
+ commonConfig.CurrTask = commonConfig.PlatformConfigStruct{}
|
|
|
+ c_log.GlobalLogger.Error("采集程序已经停止:", err)
|
|
|
continue
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- if commonConfig.CurrTask.TaskConfigId == task.TaskConfigId {
|
|
|
- break
|
|
|
+ reply := 0
|
|
|
+ if err = KillRpcClient.Call("KillService.Kill", killArgs, &reply); err != nil {
|
|
|
+ c_log.GlobalLogger.Error("发送rpc请求到master失败:", err)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- if commonConfig.CurrTask.TaskConfigId != "" {
|
|
|
- c_log.GlobalLogger.Info("需要执行的任务id为", task.TaskConfigId, ", 当前任务id为:", commonConfig.CurrTask.TaskConfigId, ", 需要杀死该任务。")
|
|
|
-
|
|
|
- var killArgs commonService.KillSignal
|
|
|
-
|
|
|
- killArgs = commonService.KillSignal{DropUploadData: true, Restart: false}
|
|
|
- c_log.GlobalLogger.Info("杀死任务,发送rpc结束信号到本地:", killArgs)
|
|
|
- KillRpcClient, err := rpc.Dial("tcp", commonConfig.LocalConfig.Node.Ip+":"+commonConfig.CloudConfig.RpcPort)
|
|
|
- if err != nil {
|
|
|
-
|
|
|
- commonConfig.RecordTopics = []string{}
|
|
|
- commonConfig.CurrTask = commonConfig.PlatformConfigStruct{}
|
|
|
- c_log.GlobalLogger.Error("采集程序已经停止:", err)
|
|
|
- continue
|
|
|
- }
|
|
|
- reply := 0
|
|
|
- if err = KillRpcClient.Call("KillService.Kill", killArgs, &reply); err != nil {
|
|
|
- c_log.GlobalLogger.Error("发送rpc请求到master失败:", err)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- c_log.GlobalLogger.Info("结束任务后,将数据闭环平台配置置空。")
|
|
|
- commonConfig.RecordTopics = []string{}
|
|
|
- commonConfig.CurrTask = commonConfig.PlatformConfigStruct{}
|
|
|
- if err = KillRpcClient.Close(); err != nil {
|
|
|
-
|
|
|
- }
|
|
|
+ c_log.GlobalLogger.Info("结束任务后,将数据闭环平台配置置空。")
|
|
|
+ commonConfig.CurrTask = commonConfig.PlatformConfigStruct{}
|
|
|
+ if err = KillRpcClient.Close(); err != nil {
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- startMasterOrSlave()
|
|
|
- commonConfig.RecordTopics = getUniqueCollectionTopics(task.TaskTriggers)
|
|
|
- commonConfig.CurrTask = task
|
|
|
-
|
|
|
- break
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ startMasterOrSlave()
|
|
|
+ commonConfig.CurrTask = task
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -117,57 +101,3 @@ func startMasterOrSlave() {
|
|
|
}
|
|
|
c_log.GlobalLogger.Info("启动任务,本地执行启动命令:【path】=", commonConfig.LocalConfig.RestartCmd.Dir, "【cmd】=", commonConfig.LocalConfig.RestartCmd.Name, commonConfig.LocalConfig.RestartCmd.Args)
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-func shouldExecuteTask(startTimeStr, endTimeStr string) bool {
|
|
|
-
|
|
|
- timeFormat := "2006-01-02 15:04:05"
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- startTime, err := time.ParseInLocation(timeFormat, startTimeStr, time.Local)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Error parsing startTime:", err)
|
|
|
- return false
|
|
|
- }
|
|
|
- endTime, err := time.ParseInLocation(timeFormat, endTimeStr, time.Local)
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- fmt.Println("Error parsing endTime:", err)
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- currentTime := time.Now()
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- return !currentTime.Before(startTime) && !currentTime.After(endTime)
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-func getUniqueCollectionTopics(taskTriggers []commonConfig.TaskTrigger) []string {
|
|
|
-
|
|
|
- topicMap := make(map[string]struct{})
|
|
|
-
|
|
|
-
|
|
|
- for _, trigger := range taskTriggers {
|
|
|
-
|
|
|
- topics := strings.Split(trigger.CollectionTopic, ",")
|
|
|
- for _, topic := range topics {
|
|
|
- trimmedTopic := strings.TrimSpace(topic)
|
|
|
- if trimmedTopic != "" {
|
|
|
- topicMap[trimmedTopic] = struct{}{}
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- var uniqueTopics []string
|
|
|
- for topic := range topicMap {
|
|
|
- uniqueTopics = append(uniqueTopics, topic)
|
|
|
- }
|
|
|
-
|
|
|
- return uniqueTopics
|
|
|
-}
|