mirror of
https://codeberg.org/superseriousbusiness/gotosocial.git
synced 2024-12-27 03:18:16 +03:00
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
|
package cron
|
||
|
|
||
|
import (
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
// Option represents a modification to the default behavior of a Cron.
|
||
|
type Option func(*Cron)
|
||
|
|
||
|
// WithLocation overrides the timezone of the cron instance.
|
||
|
func WithLocation(loc *time.Location) Option {
|
||
|
return func(c *Cron) {
|
||
|
c.location = loc
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// WithSeconds overrides the parser used for interpreting job schedules to
|
||
|
// include a seconds field as the first one.
|
||
|
func WithSeconds() Option {
|
||
|
return WithParser(NewParser(
|
||
|
Second | Minute | Hour | Dom | Month | Dow | Descriptor,
|
||
|
))
|
||
|
}
|
||
|
|
||
|
// WithParser overrides the parser used for interpreting job schedules.
|
||
|
func WithParser(p ScheduleParser) Option {
|
||
|
return func(c *Cron) {
|
||
|
c.parser = p
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// WithChain specifies Job wrappers to apply to all jobs added to this cron.
|
||
|
// Refer to the Chain* functions in this package for provided wrappers.
|
||
|
func WithChain(wrappers ...JobWrapper) Option {
|
||
|
return func(c *Cron) {
|
||
|
c.chain = NewChain(wrappers...)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// WithLogger uses the provided logger.
|
||
|
func WithLogger(logger Logger) Option {
|
||
|
return func(c *Cron) {
|
||
|
c.logger = logger
|
||
|
}
|
||
|
}
|