option.go 992 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package cron
  2. import (
  3. "log"
  4. "time"
  5. )
  6. // Option represents a modification to the default behavior of a Cron.
  7. type Option func(*Cron)
  8. // WithLocation overrides the timezone of the cron instance.
  9. func WithLocation(loc *time.Location) Option {
  10. return func(c *Cron) {
  11. c.location = loc
  12. }
  13. }
  14. // WithSeconds overrides the parser used for interpreting job schedules to
  15. // include a seconds field as the first one.
  16. func WithSeconds() Option {
  17. return WithParser(NewParser(
  18. Second | Minute | Hour | Dom | Month | Dow | Descriptor,
  19. ))
  20. }
  21. // WithParser overrides the parser used for interpreting job schedules.
  22. func WithParser(p Parser) Option {
  23. return func(c *Cron) {
  24. c.parser = p
  25. }
  26. }
  27. // WithPanicLogger overrides the logger used for logging job panics.
  28. func WithPanicLogger(l *log.Logger) Option {
  29. return func(c *Cron) {
  30. c.logger = PrintfLogger(l)
  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. }