service.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package service
  2. import (
  3. "context"
  4. "sync"
  5. "go-common/app/job/main/search/conf"
  6. "go-common/app/job/main/search/dao/base"
  7. "go-common/app/job/main/search/model"
  8. "go-common/library/log"
  9. )
  10. var (
  11. ctx = context.TODO()
  12. )
  13. const (
  14. _bulkSize = 5000
  15. )
  16. // Service .
  17. type Service struct {
  18. c *conf.Config
  19. // base
  20. base *base.Base
  21. //mutex
  22. mutex *sync.RWMutex
  23. // stats
  24. stats map[string]*model.Stat
  25. }
  26. // New .
  27. func New(c *conf.Config) (s *Service) {
  28. s = &Service{
  29. c: c,
  30. base: base.NewBase(c),
  31. mutex: new(sync.RWMutex),
  32. stats: make(map[string]*model.Stat),
  33. }
  34. s.incrproc()
  35. return
  36. }
  37. // incrproc incr data
  38. func (s *Service) incrproc() {
  39. for appid, e := range s.base.D.AppPool {
  40. if !s.base.D.BusinessPool[appid].IncrOpen {
  41. continue
  42. }
  43. if e.Business() == s.c.Business.Env && !s.c.Business.Index {
  44. go s.incr(ctx, e)
  45. }
  46. }
  47. }
  48. // Close .
  49. func (s *Service) Close() {
  50. s.base.D.Close()
  51. }
  52. // Ping .
  53. func (s *Service) Ping(c context.Context) error {
  54. return s.base.D.Ping(c)
  55. }
  56. // HTTPAction http action
  57. func (s *Service) HTTPAction(ctx context.Context, appid, action string, recoverID int64, writeEntityIndex bool) (msg string, err error) {
  58. switch action {
  59. case "repair":
  60. case "all":
  61. if _, ok := s.base.D.AppPool[appid]; !ok {
  62. msg = "appid不在appPool中"
  63. log.Error("AppPool inclueds (%v)", s.base.D.AppPool)
  64. return
  65. }
  66. s.base.D.SetRecover(ctx, appid, recoverID, "", 0)
  67. go s.all(context.Background(), appid, writeEntityIndex)
  68. default:
  69. return
  70. }
  71. return
  72. }
  73. // Stat .
  74. func (s *Service) Stat(ctx context.Context, appid string) (st *model.Stat, err error) {
  75. st = s.stat(appid)
  76. return
  77. }