service.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package service
  2. import (
  3. "context"
  4. "sync"
  5. "go-common/app/job/main/card/conf"
  6. "go-common/app/job/main/card/dao"
  7. cardCli "go-common/app/service/main/card/api/grpc/v1"
  8. "go-common/library/queue/databus"
  9. )
  10. const (
  11. _updateAction = "update"
  12. _tableUserInfo = "vip_user_info"
  13. )
  14. // Service struct
  15. type Service struct {
  16. c *conf.Config
  17. waiter *sync.WaitGroup
  18. dao *dao.Dao
  19. vipConsumer *databus.Databus
  20. // card service
  21. cardRPC cardCli.CardClient
  22. }
  23. // New init
  24. func New(c *conf.Config) (s *Service) {
  25. s = &Service{
  26. c: c,
  27. dao: dao.New(c),
  28. waiter: new(sync.WaitGroup),
  29. }
  30. cardRPC, err := cardCli.NewClient(c.CardRPC)
  31. if err != nil {
  32. panic(err)
  33. }
  34. s.cardRPC = cardRPC
  35. if c.Databus.Vip != nil {
  36. s.vipConsumer = databus.New(c.Databus.Vip)
  37. s.waiter.Add(1)
  38. go s.vipchangeproc()
  39. }
  40. return s
  41. }
  42. // Ping Service
  43. func (s *Service) Ping(c context.Context) (err error) {
  44. return s.dao.Ping(c)
  45. }
  46. // Close Service
  47. func (s *Service) Close() {
  48. if s.c.Databus.Vip != nil {
  49. s.vipConsumer.Close()
  50. }
  51. s.dao.Close()
  52. }
  53. // Wait wait all chan close
  54. func (s *Service) Wait() {
  55. s.waiter.Wait()
  56. }