service.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/ep/saga/conf"
  5. "go-common/app/admin/ep/saga/dao"
  6. "go-common/app/admin/ep/saga/service/gitlab"
  7. "go-common/app/admin/ep/saga/service/wechat"
  8. "github.com/robfig/cron"
  9. )
  10. // Service struct
  11. type Service struct {
  12. dao *dao.Dao
  13. gitlab *gitlab.Gitlab
  14. git *gitlab.Gitlab
  15. cron *cron.Cron
  16. wechat *wechat.Wechat
  17. }
  18. // New a DirService and return.
  19. func New() (s *Service) {
  20. var (
  21. err error
  22. )
  23. s = &Service{
  24. dao: dao.New(),
  25. cron: cron.New(),
  26. }
  27. if err = s.cron.AddFunc(conf.Conf.Property.SyncProject.CheckCron, s.collectprojectproc); err != nil {
  28. panic(err)
  29. }
  30. if err = s.cron.AddFunc(conf.Conf.Property.Git.CheckCron, s.alertProjectPipelineProc); err != nil {
  31. panic(err)
  32. }
  33. if err = s.cron.AddFunc(conf.Conf.Property.SyncData.CheckCron, s.syncdataproc); err != nil {
  34. panic(err)
  35. }
  36. if err = s.cron.AddFunc(conf.Conf.Property.SyncData.CheckCronAll, s.syncalldataproc); err != nil {
  37. panic(err)
  38. }
  39. if err = s.cron.AddFunc(conf.Conf.Property.SyncData.CheckCronWeek, s.syncweekdataproc); err != nil {
  40. panic(err)
  41. }
  42. s.cron.Start()
  43. // init gitlab client
  44. s.gitlab = gitlab.New(conf.Conf.Property.Gitlab.API, conf.Conf.Property.Gitlab.Token)
  45. // init online gitlab client
  46. s.git = gitlab.New(conf.Conf.Property.Git.API, conf.Conf.Property.Git.Token)
  47. // init wechat client
  48. s.wechat = wechat.New(s.dao)
  49. return
  50. }
  51. // Ping check dao health.
  52. func (s *Service) Ping(c context.Context) (err error) {
  53. return s.dao.Ping(c)
  54. }
  55. // Wait wait all closed.
  56. func (s *Service) Wait() {
  57. }
  58. // Close close all dao.
  59. func (s *Service) Close() {
  60. s.dao.Close()
  61. }