package main import ( "cicv-data-closedloop/pjisuv_ticker" "fmt" "sync" "time" ) var ( threshold float64 = 40.0 apiKey = "f9d230f00d9ccdba49a97e043333d410" maxRetries = 5 retryDelay = time.Second * 2 ) type Weather struct { WeatherID []int temperature float64 humidity float64 } // 定时任务触发器固定的 func Topic() string { return pjisuv_ticker.TickerTopic } // ******* 禁止存在下划线_ // 触发器标记 func Label() string { return "HeavyIntensityRain" } func Rule(shareVars *sync.Map) { defer func() { if r := recover(); r != nil { fmt.Println("Recovered from panic:", r) } }() // 1 使用goroutine go func(shareVars *sync.Map) { // 2 定义触发器的间隔时间 ticker := time.NewTicker(time.Duration(120) * time.Second) defer ticker.Stop() // 3 运行一个无限循环 for { select { // 定时器触发时执行的代码 case <-ticker.C: FinalCallback(shareVars) } } }(shareVars) } func FinalCallback(shareVars *sync.Map) { OutsideWorkshopFlag, ok := shareVars.Load("OutsideWorkshopFlag") Weather2, ok2 := shareVars.Load("Weather") if ok && ok2 && OutsideWorkshopFlag.(bool) == true { NOwWeather := Weather2.(Weather) if NOwWeather.WeatherID != nil { for _, weatherid := range NOwWeather.WeatherID { if weatherid == 502 || weatherid == 503 || weatherid == 504 || weatherid == 511 || weatherid == 522 { eventLabel := "HeavyIntensityRain" fmt.Println(eventLabel) pjisuv_ticker.TickerChan <- pjisuv_ticker.TickInfo{FaultLabel: Label(), FaultHappenTime: pjisuv_ticker.GetNowTimeCustom()} break } } } } }