service.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/job/main/passport-auth/conf"
  5. "go-common/app/job/main/passport-auth/dao"
  6. auth "go-common/app/service/main/passport-auth/rpc/client"
  7. "go-common/library/queue/databus"
  8. "go-common/library/queue/databus/databusutil"
  9. )
  10. // Service struct
  11. type Service struct {
  12. c *conf.Config
  13. dao *dao.Dao
  14. g *databusutil.Group
  15. oldAuthConsumer *databus.Databus
  16. authRPC *auth.Service
  17. authConsumer *databus.Databus
  18. authGroup *databusutil.Group
  19. }
  20. // New init
  21. func New(c *conf.Config) (s *Service) {
  22. s = &Service{
  23. c: c,
  24. dao: dao.New(c),
  25. oldAuthConsumer: databus.New(c.Databus),
  26. authRPC: auth.New(c.AuthRPC),
  27. authConsumer: databus.New(c.AuthDataBus),
  28. }
  29. // new a group
  30. s.g = databusutil.NewGroup(
  31. c.DatabusUtil,
  32. s.oldAuthConsumer.Messages(),
  33. )
  34. s.authGroup = databusutil.NewGroup(
  35. c.DatabusUtil,
  36. s.authConsumer.Messages(),
  37. )
  38. s.consumeproc()
  39. s.authConsumeProc()
  40. // go s.syncCookie()
  41. // for i := c.IDXFrom; i < c.IDXTo; i ++ {
  42. // go s.syncCookie(int64(i))
  43. // }
  44. // go s.syncToken("201804", 0, 50000000)
  45. // go s.syncToken("201804", 50000001, 100000000)
  46. // go s.syncToken("201804", 100000001, 150000000)
  47. // go s.syncToken("201804", 150000001, 0)
  48. return s
  49. }
  50. // Ping Service
  51. func (s *Service) Ping(c context.Context) (err error) {
  52. return s.dao.Ping(c)
  53. }
  54. // Close Service
  55. func (s *Service) Close() {
  56. s.g.Close()
  57. s.authGroup.Close()
  58. s.dao.Close()
  59. }