component.go 563 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package mhayaCron
  2. import (
  3. cfacade "github.com/mhaya/facade"
  4. clog "github.com/mhaya/logger"
  5. "github.com/robfig/cron/v3"
  6. )
  7. const (
  8. Name = "cron_component"
  9. )
  10. type Component struct {
  11. cfacade.Component
  12. }
  13. // Name unique components name
  14. func (*Component) Name() string {
  15. return Name
  16. }
  17. func (p *Component) Init() {
  18. Start()
  19. clog.Info("cron component init.")
  20. }
  21. func (p *Component) OnStop() {
  22. Stop()
  23. clog.Infof("cron component is stopped.")
  24. }
  25. func New(opts ...cron.Option) cfacade.IComponent {
  26. if len(opts) > 0 {
  27. Init(opts...)
  28. }
  29. return &Component{}
  30. }