Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrAlreadyExists = errors.New("already exists")
)
Functions ¶
This section is empty.
Types ¶
type Cron ¶
type Cron struct {
// contains filtered or unexported fields
}
Cron is a fault-tolerant job scheduler.
func (*Cron) Add ¶
Add adds a job with the given properties. If name already exists, Add will return ErrAlreadyExists, otherwise it will return nil.
Note that the execution interval of the job, which is specified by expr, must be greater than LockTTL.
type Job ¶
type Job struct { // The unique name of the job. Name string // The cron expression. Three formats are supported currently: // // 1. Fixed-interval schedule: // // @every <duration> // // where `<duration>` is a string accepted by `time.ParseDuration` (http://golang.org/pkg/time/#ParseDuration). // // 2. Predefined cron expression (https://github.com/gorhill/cronexpr#predefined-cron-expressions): // // @annually // @yearly // @monthly // @weekly // @daily // @hourly // // 3. Standard cron expression (https://github.com/gorhill/cronexpr#implementation). // // Note that the execution interval of the job must be greater than LockTTL. Expr string // The old-style handler of the job. Task func() // The new-style handler of the job. // // Note that Handler will be preferred if both Task and Handler are specified. Handler func(context.Context) error }
Job represents a normal job, which will be scheduled by Cron.
type Locker ¶
type Locker interface { // Lock obtains the lock to execute the job named job. If the lock is // successfully obtained, Lock will return true, otherwise it will return false. // // The implementation of Locker must release the obtained lock automatically // after ttl elapses. Lock(job string, ttl time.Duration) (bool, error) }
Locker is a distributed lock.
type NilLocker ¶
type NilLocker struct{}
NilLocker implements a fake lock that is always obtainable.
It is intended to be used in scenarios where only one instance of Cron is needed.
func NewNilLocker ¶
func NewNilLocker() *NilLocker
type Options ¶
type Options struct { // The location name, which must be "Local", "UTC" or a location name corresponding // to a file in the IANA Time Zone database, such as "Asia/Shanghai". // // Defaults to "UTC". Timezone string // LockTTL is the time duration after which the successfully obtained lock // will be released. It is a time window used to protect a job from // being executed more than once per execution time of its schedule, // which may be caused by the clock error among different machines. // // Defaults to 1s. LockTTL time.Duration // The handler for errors. ErrHandler func(error) }
type Schedule ¶
type SemaphoreLocker ¶
type SemaphoreLocker struct {
// contains filtered or unexported fields
}
SemaphoreLocker implements a lock for in-process mutual exclusion.
It is intended to be used in scenarios where multiple instances of Cron are run in the same process.
func NewSemaphoreLocker ¶
func NewSemaphoreLocker() *SemaphoreLocker