123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package test
- import (
- commonConfig "cicv-data-closedloop/aarch64/jili/common/config"
- "cicv-data-closedloop/common/config/c_log"
- "fmt"
- "testing"
- "time"
- )
- func init() {
-
- c_log.InitLog(commonConfig.LogDir, commonConfig.ControlLogPrefix)
-
- commonConfig.InitLocalConfig()
- commonConfig.InitOssConfig()
- commonConfig.InitCloudConfig()
- }
- func TestGetConfig(t *testing.T) {
- fmt.Println(commonConfig.LocalConfig.EquipmentNo)
- PlatformConfig, err := commonConfig.GetPlatformTasks()
- fmt.Println("PlatformConfig", PlatformConfig)
- if err != nil {
- fmt.Println("获取配置status失败:", err)
- }
- }
- func TestControl(t *testing.T) {
- wait := false
-
- for {
- if wait {
- time.Sleep(time.Duration(60) * time.Second)
- }
- wait = true
-
- platformTasks, err := commonConfig.GetPlatformTasks()
- fmt.Println("platformTasks", platformTasks)
- commonConfig.PlatformTasks = platformTasks
- if err != nil {
- c_log.GlobalLogger.Error("获取平台任务失败:", err)
- continue
- }
-
- for _, task := range platformTasks {
- flag := shouldExecuteTask(task.StartTime, task.EndTime)
- fmt.Println("flag", flag)
- }
- }
- }
- func shouldExecuteTask(startTimeStr, endTimeStr string) bool {
-
- timeFormat := "2006-01-02 15:04:05"
-
- startTime, err := time.ParseInLocation(timeFormat, startTimeStr, time.Local)
- fmt.Println("startTime", startTime)
- if err != nil {
- fmt.Println("Error parsing startTime:", err)
- return false
- }
- endTime, err := time.ParseInLocation(timeFormat, endTimeStr, time.Local)
- fmt.Println("endTime", endTime)
- if err != nil {
- fmt.Println("Error parsing endTime:", err)
- return false
- }
-
- currentTime := time.Now()
- fmt.Println("currentTime", currentTime)
-
- return !currentTime.Before(startTime) && !currentTime.After(endTime)
- }
|