service.go 921 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/ep/tapd/conf"
  5. "go-common/app/admin/ep/tapd/dao"
  6. "go-common/library/sync/pipeline/fanout"
  7. "github.com/robfig/cron"
  8. )
  9. // Service struct
  10. type Service struct {
  11. c *conf.Config
  12. dao *dao.Dao
  13. transferChan *fanout.Fanout
  14. cron *cron.Cron
  15. }
  16. // New init.
  17. func New(c *conf.Config) (s *Service) {
  18. s = &Service{
  19. c: c,
  20. dao: dao.New(c),
  21. transferChan: fanout.New("cache", fanout.Worker(5), fanout.Buffer(10240)),
  22. }
  23. if s.c.Scheduler.Active {
  24. s.cron = cron.New()
  25. if err := s.cron.AddFunc(c.Scheduler.UpdateHookURLCacheTask, func() { s.dao.SaveEnableHookURLToCache() }); err != nil {
  26. panic(err)
  27. }
  28. s.cron.Start()
  29. }
  30. return
  31. }
  32. // Close Service.
  33. func (s *Service) Close() {
  34. s.dao.Close()
  35. }
  36. // Ping check server ok.
  37. func (s *Service) Ping(c context.Context) (err error) {
  38. err = s.dao.Ping(c)
  39. return
  40. }