cron

package module
v0.0.0-...-658c4ec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2023 License: MIT Imports: 8 Imported by: 0

README

cron-go

An crontab library for GoLang

References:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Appoint

type Appoint struct {
	// Time is the task execute time.
	Time time.Time
	// contains filtered or unexported fields
}

Appoint used to perform the task at a specified time.

func (*Appoint) Next

func (job *Appoint) Next(time.Time) time.Time

Next is called be timewheel.

type Crontab

type Crontab struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Crontab

New creates a Crontab.

func (*Crontab) Remove

func (cron *Crontab) Remove(key string)

Remove delete and stop the job with specified id.

func (*Crontab) Start

func (cron *Crontab) Start()

Start starts the crontab in its own goroutine

func (*Crontab) Stop

func (cron *Crontab) Stop()

Stop stops the crontab.

Notice: By default, Stop does not wait for the running job completed. You can use WrapJobWaitGroup to track the completion of jobs.

func (*Crontab) Submit

func (cron *Crontab) Submit(ctx context.Context, key string, job Job, schedule Schedule)

Submit adds or updates a job to the Crontab to be run on the given Schedule. The old job with the key will be stopped and delete if exists.

type Interval

type Interval struct {
	// Begin is the start time of the validity period of the job.
	// Zero means no limited.
	Begin time.Time

	// End is the end time of the validity period of the job.
	// Zero means no limited.
	End time.Time

	// Interval is the time interval between each task.
	// The value cannot less than 10ms.
	Interval time.Duration
}

Interval represents a periodic task with fixed interval

func (*Interval) Next

func (job *Interval) Next(prev time.Time) time.Time

Next is called be timewheel.

type Job

type Job interface {
	timewheel.Job
}

type JobChain

type JobChain []JobWrapper

JobChain is a sequence of JobWrapper that decorates submitted jobs with

func (JobChain) Apply

func (jobChain JobChain) Apply(job Job) Job

Apply decorates the given exprSchedule with all JobWrapper in the jobChain.

This:

WithJobWrapper(m1, m2, m3).Apply(Job)

is equivalent to:

m1(m2(m3(Job)))

type JobFunc

type JobFunc = timewheel.JobFunc

type JobWrapper

type JobWrapper func(job Job) Job

func WrapJobBlockIfRunning

func WrapJobBlockIfRunning() JobWrapper

WrapJobBlockIfRunning implements a JobWrapper to block an invocation of the job util the previous one is completed.

func WrapJobRecover

func WrapJobRecover() JobWrapper

WrapJobRecover implements a JobWrapper to recover when Job run panics.

func WrapJobRetry

func WrapJobRetry(ctxRetry context.Context, limit int64, interval time.Duration) JobWrapper

WrapJobRetry implements a JobWrapper to retry Run when any error. The limit < 0 means no limited. The interval not allowed must be greater than 0.

func WrapJobSkipIfRunning

func WrapJobSkipIfRunning() JobWrapper

WrapJobSkipIfRunning implements a JobWrapper to skip an invocation of the Job if previous invocation is still running.

func WrapJobWaitGroup

func WrapJobWaitGroup(wg *sync.WaitGroup) JobWrapper

WrapJobWaitGroup implements a JobWrapper to track the completion of job with sync.WaitGroup.

type Option

type Option func(cron *Crontab)

Option represents a modification to the default behavior of a Cron.

func WithJobChain

func WithJobChain(jobChain JobChain) Option

WithJobChain overwrite the jobChain.

func WithJobWrapper

func WithJobWrapper(w ...JobWrapper) Option

WithJobWrapper append JobWrapper into jobChain

func WithTimezone

func WithTimezone(loc *time.Location) Option

WithTimezone reset the timezone in Cron.

type Schedule

type Schedule interface {
	timewheel.Schedule
}

Schedule used in scheduler.

type ScheduleFunc

type ScheduleFunc = timewheel.ScheduleFunc

type Task

type Task struct {
	// Value is the arguments used with callback function.
	Value interface{}

	// Callback called when job expired.
	Callback func(ctx context.Context, value interface{}) error
}

Task represents a Job implementation.

func (*Task) Run

func (task *Task) Run(ctx context.Context) error

type UnixCron

type UnixCron struct {
	// Begin is the start time of the validity period of the job.
	// Zero means no limited.
	Begin time.Time

	// End is the end time of the validity period of the job.
	// Zero means no limited.
	End time.Time

	// Express is the crontab express specification.
	// Notice: It will panics if express is invalid.
	Express string
	// contains filtered or unexported fields
}

UnixCron represents a periodic task with standard unix crontab expression.

func (*UnixCron) Next

func (job *UnixCron) Next(prev time.Time) time.Time

Next is called be timewheel.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL