123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- package data
- import (
- "eta/eta_api/models/data_manage"
- "eta/eta_api/services/alarm_msg"
- "eta/eta_api/utils"
- "fmt"
- "sync"
- )
- var (
- EdbRefreshLock sync.Map
- EdbRefreshHandling chan EdbQueueRefreshReq
- EdbRefreshWorker chan struct{}
- )
- func init() {
- EdbRefreshHandling = make(chan EdbQueueRefreshReq, 50)
- EdbRefreshWorker = make(chan struct{}, 5)
- }
- type EdbQueueRefreshReq struct {
- RefreshKey string `description:"刷新请求的缓存key"`
- ItemRefreshKeys []string `description:"图表/表格刷新后要删除的缓存key"`
- BaseEdbInfoArr []*data_manage.EdbInfo
- BasePredictEdbInfoArr []*data_manage.EdbInfo
- CalculateMap map[int]*data_manage.EdbInfo
- PredictCalculateMap map[int]*data_manage.EdbInfo
- CalculateArr []int
- PredictCalculateArr []int
- }
- func PushEdb2Refresh(item EdbQueueRefreshReq) {
- refreshKey := item.RefreshKey
- if refreshKey == "" {
- return
- }
-
- _, ok := EdbRefreshLock.Load(refreshKey)
- if ok {
- return
- }
-
- EdbRefreshHandling <- item
- EdbRefreshLock.Store(refreshKey, true)
- }
- func HandleEdbRefreshQueue() {
- defer func() {
- if err := recover(); err != nil {
- tips := fmt.Sprintf("[HandleEdbRefreshQueue] panic: %v", err)
- fmt.Println(tips)
- utils.FileLog.Info(tips)
- }
- }()
- fmt.Println("HandleEdbRefreshQueue start")
- for {
- select {
- case item, ok := <-EdbRefreshHandling:
- if !ok {
- return
- }
- go EdbRefreshTask(item)
- }
- }
- }
- func EdbRefreshTask(item EdbQueueRefreshReq) {
- var err error
- defer func() {
- if err != nil {
- tips := fmt.Sprintf("[EdbRefreshTask] ErrMsg: %s", err.Error())
- utils.FileLog.Info(tips)
- go alarm_msg.SendAlarmMsg(tips, 3)
- }
- <-EdbRefreshWorker
- }()
- EdbRefreshWorker <- struct{}{}
- fmt.Printf("EdbRefreshTask开始刷新: %s\n", item.RefreshKey)
-
- e := edbInfoRefreshAll(false, item.BaseEdbInfoArr, item.BasePredictEdbInfoArr, item.CalculateMap, item.PredictCalculateMap, item.CalculateArr, item.PredictCalculateArr)
- if e != nil {
- err = fmt.Errorf("edbInfoRefreshAll err: %s", e.Error())
- }
-
- _ = utils.Rc.Delete(item.RefreshKey)
- if len(item.ItemRefreshKeys) > 0 {
- for _, v := range item.ItemRefreshKeys {
- _ = utils.Rc.Delete(v)
- }
- }
-
- EdbRefreshLock.Delete(item.RefreshKey)
- fmt.Printf("EdbRefreshTask结束刷新: %s\n", item.RefreshKey)
- }
|