option.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package cron
  2. import (
  3. "time"
  4. )
  5. // Option represents a modification to the default behavior of a Cron.
  6. type Option func(*Cron)
  7. // WithLocation overrides the timezone of the cron instance.
  8. func WithLocation(loc *time.Location) Option {
  9. return func(c *Cron) {
  10. c.location = loc
  11. }
  12. }
  13. // WithSeconds overrides the parser used for interpreting job schedules to
  14. // include a seconds field as the first one.
  15. func WithSeconds() Option {
  16. return WithParser(NewParser(
  17. Second | Minute | Hour | Dom | Month | Dow | Descriptor,
  18. ))
  19. }
  20. // WithParser overrides the parser used for interpreting job schedules.
  21. func WithParser(p ScheduleParser) Option {
  22. return func(c *Cron) {
  23. c.parser = p
  24. }
  25. }
  26. // WithChain specifies Job wrappers to apply to all jobs added to this cron.
  27. // Refer to the Chain* functions in this package for provided wrappers.
  28. func WithChain(wrappers ...JobWrapper) Option {
  29. return func(c *Cron) {
  30. c.chain = NewChain(wrappers...)
  31. }
  32. }
  33. // WithLogger uses the provided logger.
  34. func WithLogger(logger Logger) Option {
  35. return func(c *Cron) {
  36. c.logger = logger
  37. }
  38. }