service.go 908 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package service
  2. import (
  3. "context"
  4. "sync"
  5. "go-common/app/job/main/appstatic/conf"
  6. "go-common/app/job/main/appstatic/dao/caldiff"
  7. "go-common/app/job/main/appstatic/dao/push"
  8. "go-common/library/log"
  9. )
  10. var ctx = context.Background()
  11. // Service .
  12. type Service struct {
  13. c *conf.Config
  14. dao *caldiff.Dao
  15. pushDao *push.Dao
  16. waiter *sync.WaitGroup
  17. daoClosed bool
  18. }
  19. // New creates a Service instance.
  20. func New(c *conf.Config) (s *Service) {
  21. s = &Service{
  22. c: c,
  23. dao: caldiff.New(c),
  24. pushDao: push.New(c),
  25. waiter: new(sync.WaitGroup),
  26. }
  27. s.waiter.Add(1)
  28. go s.pushproc()
  29. s.waiter.Add(1)
  30. go s.calDiffproc()
  31. return
  32. }
  33. // Close releases resources which owned by the Service instance.
  34. func (s *Service) Close() (err error) {
  35. log.Info("Close dao!")
  36. s.daoClosed = true
  37. log.Info("Wait waiter!")
  38. s.waiter.Wait()
  39. log.Info("appstatic-job has been closed.")
  40. return
  41. }