gamelistMgr.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package gamelist
  2. import (
  3. "bet24.com/log"
  4. "bet24.com/servers/transaction"
  5. "sync"
  6. "time"
  7. )
  8. func newGamelistMgr() *gamelistMgr {
  9. obj := new(gamelistMgr)
  10. obj.lock = &sync.RWMutex{}
  11. obj.refreshData()
  12. return obj
  13. }
  14. type gamelistMgr struct {
  15. games []transaction.GameInfo
  16. lock *sync.RWMutex
  17. }
  18. func (g *gamelistMgr) refreshData() {
  19. go g.doRefresh()
  20. time.AfterFunc(5*time.Minute, g.refreshData)
  21. }
  22. func (g *gamelistMgr) doRefresh() {
  23. gameList := transaction.GetGameListFromDB(false)
  24. g.lock.Lock()
  25. defer g.lock.Unlock()
  26. g.games = gameList
  27. }
  28. func (g *gamelistMgr) getGame(gameId int) *transaction.GameInfo {
  29. g.lock.RLock()
  30. defer g.lock.RUnlock()
  31. for _, v := range g.games {
  32. if v.GameID == gameId {
  33. return &v
  34. }
  35. }
  36. return nil
  37. }
  38. func (g *gamelistMgr) dump() {
  39. log.Release("-------------------------------")
  40. log.Release("gamelistMgr.dump")
  41. defer func() {
  42. log.Release("+++++++++++++++++++++++++++++++")
  43. log.Release("")
  44. }()
  45. g.lock.RLock()
  46. g.lock.RUnlock()
  47. for _, v := range g.games {
  48. log.Release(" %v", v)
  49. }
  50. }