Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AfterFunc ¶
type AfterFunc func(task Task)
AfterFunc represents the function could be called after Run.
type Atomic ¶ added in v0.3.0
type Atomic interface { // SetIfNotExists stores the key/value and return true if the key is not existed, // or does nothing and return false. // Note that the key/value should be kept for at least one minute. // For example, `SetNX(key, value, time.Minute)` via redis. SetIfNotExists(ctx context.Context, key, value string) bool }
Atomic provides distributed atomic operation for dcron, it can be implemented easily via Redis/SQL and so on.
type BeforeFunc ¶
BeforeFunc represents the function could be called before Run.
type Cron ¶
type Cron struct {
// contains filtered or unexported fields
}
Cron keeps track of any number of jobs, invoking the associated func as specified.
func NewCron ¶
func NewCron(options ...CronOption) *Cron
NewCron returns a cron with specified options.
func (*Cron) Start ¶
func (c *Cron) Start()
Start the cron scheduler in its own goroutine, or no-op if already started.
func (*Cron) Statistics ¶ added in v0.5.0
func (c *Cron) Statistics() Statistics
Statistics implements CronMeta.Statistics
type CronMeta ¶
type CronMeta interface { // Key returns the unique key of the cron. Key() string // Hostname returns current hostname. Hostname() string // Statistics returns statistics info of the cron's all jobs. Statistics() Statistics // Jobs returns the cron's all jobs as JobMeta. Jobs() []JobMeta }
CronMeta is a read only wrapper for Cron.
type CronOption ¶
type CronOption func(c *Cron)
CronOption represents a modification to the default behavior of a Cron.
func WithAtomic ¶ added in v0.3.0
func WithAtomic(atomic Atomic) CronOption
WithAtomic uses the provided Atomic.
func WithContext ¶ added in v1.4.0
func WithContext(ctx context.Context) CronOption
WithContext sets the root context of the cron instance. It will be used as the parent context of all tasks, and when the context is done, the cron will be stopped.
func WithHostname ¶
func WithHostname(hostname string) CronOption
WithHostname overrides the hostname of the cron instance.
func WithLocation ¶ added in v0.5.0
func WithLocation(loc *time.Location) CronOption
WithLocation overrides the timezone of the cron instance.
type Job ¶
type Job interface { // Key returns the unique key of the job. Key() string // Spec returns spec of the job, like "* * * * * *". Spec() string // Run is what the job do. Run(ctx context.Context) error // Options returns options of the job. Options() []JobOption }
Job describes a type which could be added to a cron.
func NewJobWithAutoKey ¶ added in v0.4.0
NewJobWithAutoKey returns a new Job with the "run" function's name as key. Be careful, the "run" should be a non-anonymous function, or returned Job will have an emtpy key, and can not be added to a Cron.
type JobMeta ¶
type JobMeta interface { // Key returns the unique key of the job. Key() string // Spec returns the spec of the job. Spec() string // Statistics returns statistics info of the job. Statistics() Statistics }
JobMeta is a read only wrapper for innerJob.
type JobOption ¶
type JobOption func(job *innerJob)
JobOption represents a modification to the default behavior of a Job.
func WithAfterFunc ¶
WithAfterFunc specifies what to do after Run.
func WithBeforeFunc ¶
func WithBeforeFunc(before BeforeFunc) JobOption
WithBeforeFunc specifies what to do before Run.
func WithNoMutex ¶ added in v0.2.1
func WithNoMutex() JobOption
WithNoMutex means the job will run at multiple cron instances, even though the cron has Atomic.
func WithRetryInterval ¶
func WithRetryInterval(retryInterval RetryInterval) JobOption
WithRetryInterval indicates how long should delay before retrying when run failed `triedTimes` times.
func WithRetryTimes ¶
WithRetryTimes specifies max times to retry, retryTimes will be set as 1 if it is less than 1.
type RetryInterval ¶
RetryInterval indicates how long should delay before retrying when run failed `triedTimes` times.
type Statistics ¶ added in v0.5.0
type Statistics struct { TotalTask int64 // Total count of tasks processed PassedTask int64 // Number of tasks successfully executed FailedTask int64 // Number of tasks that failed during execution due to errors SkippedTask int64 // Number of tasks skipped due to BeforeFunc returning true MissedTask int64 // Number of tasks executed by other instances TotalRun int64 // Total count of execution runs PassedRun int64 // Number of successfully executed runs FailedRun int64 // Number of runs that have failed due to errors RetriedRun int64 // Number of runs that encountered errors and were subsequently retried }
Statistics records statistics info for a cron or a job.
func (Statistics) Add ¶ added in v1.0.0
func (s Statistics) Add(delta Statistics) Statistics
Add return a new Statistics with two added.