ticker := time.NewTicker(5 * 60 * time.Second) defer ticker.Stop() for { if h.NeedRun() { g, _ := errgroup.WithContext(h.ctx) g.Go(func()error { h.AssetInfer() returnnil }) g.Go(func()error { h.GenMiddleTable() returnnil }) if err := g.Wait(); err != nil { mlog.Warnf("asset infer run exit: %v", err) } return } select { case <-h.ctx.Done(): mlog.Info("asset infer handler stop") return case <-ticker.C: } } }
不需要,原来的loop版本,就是等待NeedRun,为true,就去执行两个协程,然后
[mysql] 2025/11/22 23:04:45 packets.go:36: unexpected EOF {“level”:”warn”,”time”:”2025-11-22T23:04:45.769+0800”,”position”:”handler/asset_infer_handler.go:848”,”function”:”sangfor.com/xdr/asm-cron/internal/assetinfer/handler.(AssetInferHandler).genMiddleResult”,”message”:”query:SELECT dstAssetId, regexp_extract(responseBody, ‘(.?)‘, 1) as title, CAST(count(*) AS BIGINT), max(recordTimestamp) as maxRecordTimestamp, any_value(if(instr(url, ‘?’) > 0, substring(url, 1, instr(url, ‘?’) - 1), url)) As url FROM business.http_log WHERE respStatus = 200 AND recordTimestamp >= 1763654400 AND recordTimestamp < 1763740800 AND respContentType = ‘text/html’ AND instr(responseBody, ‘
‘) > 0 GROUP BY dstAssetId, title LIMIT 300000;, query failed,err:Error 1064: Failed to allocate resource to query: org.apache.thrift.transport.TTransportException: Socket is closed by peer., will retry 3 times”}