empty_arc.go 820 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package view
  2. import (
  3. "time"
  4. "go-common/library/log"
  5. )
  6. func (s *Service) emptyArcproc() {
  7. var (
  8. ps = s.conf.Cfg.EmptyArc.UnshelvePS
  9. emptyAids = make(map[int64]int, ps)
  10. )
  11. for {
  12. aid, ok := <-s.emptyArcCh
  13. if !ok {
  14. log.Warn("[emptyArcproc] channel quit")
  15. return
  16. }
  17. emptyAids[aid] = 1
  18. if len(emptyAids) < ps { // not enough cid, stay waiting
  19. time.Sleep(2 * time.Second)
  20. continue
  21. }
  22. distinctAIDs := pickKeys(emptyAids)
  23. emptyAids = make(map[int64]int, ps)
  24. if err := s.cmsDao.UnshelveArcs(ctx, distinctAIDs); err != nil {
  25. log.Error("emptyArc Aids %v, Err %v", distinctAIDs, err)
  26. continue
  27. }
  28. log.Info("emptyArc Apply %d Aids: %v", len(distinctAIDs), distinctAIDs)
  29. }
  30. }
  31. func pickKeys(q map[int64]int) (res []int64) {
  32. for k := range q {
  33. res = append(res, k)
  34. }
  35. return
  36. }