round.go 876 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/library/log"
  6. )
  7. func (s *Service) roundproc() {
  8. defer s.wg.Done()
  9. for {
  10. if s.closed {
  11. return
  12. }
  13. s.roundToEnd()
  14. time.Sleep(5 * time.Minute)
  15. }
  16. }
  17. func (s *Service) roundToEnd() {
  18. var (
  19. err error
  20. rows int64
  21. now = time.Now()
  22. minTime = s.delayRoundMinTime
  23. maxTime time.Time
  24. c = context.TODO()
  25. )
  26. if s.roundDelayCache == 0 {
  27. log.Error("roundEnd conf is 0")
  28. return
  29. }
  30. if s.delayRoundMinTime.IsZero() {
  31. minTime = now.Add(-time.Duration(s.roundDelayCache)*24*time.Hour - time.Hour)
  32. }
  33. maxTime = now.Add(-time.Duration(s.roundDelayCache) * 24 * time.Hour)
  34. if rows, err = s.arc.UpDelayRound(c, minTime, maxTime); err != nil {
  35. return
  36. }
  37. s.delayRoundMinTime = maxTime
  38. log.Info("round auto change to end(99),startTime(%v),endTime(%v),affected(%d)", minTime, maxTime, rows)
  39. }