Browse Source

环节处理改为批处理

dev
yfh 2 months ago
parent
commit
c6f66e56ce
  1. 29
      et_cache/cacheHandler.go

29
et_cache/cacheHandler.go

@ -5,10 +5,9 @@ import (
"fmt" "fmt"
"gitea.anxinyun.cn/container/common_models" "gitea.anxinyun.cn/container/common_models"
"gitea.anxinyun.cn/container/common_models/constant/redisKey" "gitea.anxinyun.cn/container/common_models/constant/redisKey"
"gitea.anxinyun.cn/container/common_utils"
"gitea.anxinyun.cn/container/common_utils/configLoad"
"log" "log"
"node/stages" "node/stages"
"sync"
) )
type CacheHandler struct { type CacheHandler struct {
@ -16,19 +15,33 @@ type CacheHandler struct {
stage *stages.Stage stage *stages.Stage
} }
func NewCacheHandler() *CacheHandler { func NewCacheHandler(cacheServer *cacheSer.CacheServer) *CacheHandler {
redisAddr := configLoad.LoadConfig().GetString("redis.address") //redisAddr := configLoad.LoadConfig().GetString("redis.address")
configHelper := common_utils.NewConfigHelper(redisAddr) //configHelper := common_utils.NewConfigHelper(redisAddr)
the := &CacheHandler{ the := &CacheHandler{
stage: stages.NewStage("测点数据缓存"), stage: stages.NewStage("滑窗过滤"),
cacheServer: cacheSer.NewCacheServer(configHelper), cacheServer: cacheServer, //cacheSer.NewCacheServer(configHelper),
} }
the.stage.AddProcess(the.enqueue) the.stage.AddProcess(the.enqueueForStations)
return the return the
} }
func (the *CacheHandler) GetStage() stages.Stage { func (the *CacheHandler) GetStage() stages.Stage {
return *the.stage return *the.stage
} }
func (the *CacheHandler) enqueueForStations(data []*common_models.ProcessData) []*common_models.ProcessData {
var wg sync.WaitGroup // 初始化 WaitGroup
for _, processData := range data {
wg.Add(1)
go func(pd *common_models.ProcessData) {
defer wg.Done()
the.enqueue(pd)
}(processData)
}
wg.Wait()
return data
}
func (the *CacheHandler) enqueue(p *common_models.ProcessData) *common_models.ProcessData { func (the *CacheHandler) enqueue(p *common_models.ProcessData) *common_models.ProcessData {
for _, station := range p.Stations { for _, station := range p.Stations {

Loading…
Cancel
Save