git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/cron/option.go (about)

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