schedule

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const MAXJOBNUM = 1000

Variables

View Source
var (
	ErrTimeFormat           = errors.New("time format error")
	ErrParamsNotAdapted     = errors.New("the number of params is not adapted")
	ErrNotAFunction         = errors.New("only functions can be schedule into the job queue")
	ErrPeriodNotSpecified   = errors.New("unspecified job period")
	ErrParameterCannotBeNil = errors.New("nil parameters cannot be used with reflection")
)

Functions

func Clear

func Clear()

Clear all scheduled jobs

func Remove

func Remove(j interface{})

Remove a specific job

func RunAll

func RunAll()

RunAll run all jobs regardless if they are scheduled to run or not.

func RunAllwithDelay

func RunAllwithDelay(d int)

RunAllwithDelay run all the jobs with a delay in seconds

A delay of `delay` seconds is added between each job. This can help to distribute the system load generated by the jobs more evenly over time.

func RunPending

func RunPending()

RunPending run all jobs that are scheduled to run

Please note that it is *intended behavior that run_pending() does not run missed jobs*. For example, if you've registered a job that should run every minute and you only call run_pending() in one hour increments then your job won't be run 60 times in between but only once.

func Scheduled

func Scheduled(j interface{}) bool

Scheduled checks if specific job j was already added

func SetLocker

func SetLocker(l Locker)

func Start

func Start() chan bool

Start run all jobs that are scheduled to run

Types

type Locker

type Locker interface {
	Lock(key string) (bool, error)
	Unlock(key string) error
}

type Scheduler

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

Scheduler struct, the only data member is the list of jobs.

func NewScheduler

func NewScheduler() *Scheduler

NewScheduler creates a new scheduler

func (*Scheduler) ChangeLoc

func (s *Scheduler) ChangeLoc(newLocation *time.Location)

ChangeLoc changes the default time location

func (*Scheduler) Clear

func (s *Scheduler) Clear()

Clear delete all scheduled jobs

func (*Scheduler) Every

func (s *Scheduler) Every(interval uint64) *Task

Every schedule a new periodic job with interval

func (*Scheduler) Len

func (s *Scheduler) Len() int

func (*Scheduler) Less

func (s *Scheduler) Less(i, j int) bool

func (*Scheduler) NextRun

func (s *Scheduler) NextRun() (*Task, time.Time)

NextRun datetime when the next job should run.

func (*Scheduler) Remove

func (s *Scheduler) Remove(j interface{})

Remove specific job j by function

func (*Scheduler) RemoveByRef

func (s *Scheduler) RemoveByRef(j *Task)

RemoveByRef removes specific job j by reference

func (*Scheduler) RemoveByTag

func (s *Scheduler) RemoveByTag(t string)

RemoveByTag removes specific job j by tag

func (*Scheduler) RunAll

func (s *Scheduler) RunAll()

RunAll run all jobs regardless if they are scheduled to run or not

func (*Scheduler) RunAllwithDelay

func (s *Scheduler) RunAllwithDelay(d int)

RunAllwithDelay runs all jobs with delay seconds

func (*Scheduler) RunPending

func (s *Scheduler) RunPending()

RunPending runs all the jobs that are scheduled to run.

func (*Scheduler) Scheduled

func (s *Scheduler) Scheduled(j interface{}) bool

Scheduled checks if specific job j was already added

func (*Scheduler) Start

func (s *Scheduler) Start() chan bool

Start all the pending jobs Add seconds ticker

func (*Scheduler) Swap

func (s *Scheduler) Swap(i, j int)

func (*Scheduler) Tasks

func (s *Scheduler) Tasks() []*Task

Tasks returns the list of Tasks from the Scheduler

type Task

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

Task struct keeping information about job

func Every

func Every(interval uint64) *Task

Every schedules a new periodic job running in specific interval

func NewTask

func NewTask(interval uint64) *Task

NewTask creates a new job with the time interval.

func NextRun

func NextRun() (job *Task, time time.Time)

NextRun gets the next running time

func (*Task) At

func (j *Task) At(t string) *Task

At schedules job at specific time of day

s.Every(1).Day().At("10:30:01").Do(task)
s.Every(1).Monday().At("10:30:01").Do(task)

func (*Task) Day

func (j *Task) Day() *Task

Day sets the job's unit with day, which interval is 1

func (*Task) Days

func (j *Task) Days() *Task

Days set the job's unit with days

func (*Task) Do

func (j *Task) Do(taskFun interface{}, params ...interface{}) error

Do specifies the taskFunc that should be called every time the job runs

func (*Task) DoSafely

func (j *Task) DoSafely(taskFun interface{}, params ...interface{}) error

DoSafely does the same thing as Do, but logs unexpected panics, instead of unwinding them up the chain Deprecated: DoSafely exists due to historical compatibility and will be removed soon. Use Do instead

func (*Task) Err

func (j *Task) Err() error

Err should be checked to ensure an error didn't occur creating the job

func (*Task) Friday

func (j *Task) Friday() *Task

Friday sets the job start day Friday

func (*Task) From

func (j *Task) From(t *time.Time) *Task

From schedules the next run of the job

func (*Task) GetAt

func (j *Task) GetAt() string

GetAt returns the specific time of day the job will run at

s.Every(1).Day().At("10:30").GetAt() == "10:30"

func (*Task) GetWeekday

func (j *Task) GetWeekday() time.Weekday

GetWeekday returns which day of the week the job will run on This should only be used when .Weekday(...) was called on the job.

func (*Task) Hour

func (j *Task) Hour() *Task

Hour sets the unit with hour, which interval is 1

func (*Task) Hours

func (j *Task) Hours() *Task

Hours set the unit with hours

func (*Task) Loc

func (j *Task) Loc(loc *time.Location) *Task

Loc sets the location for which to interpret "At"

s.Every(1).Day().At("10:30").Loc(time.UTC).Do(task)

func (*Task) Lock

func (j *Task) Lock() *Task

Lock prevents job to run from multiple instances of gocron

func (*Task) Minute

func (j *Task) Minute() *Task

Minute sets the unit with minute, which interval is 1

func (*Task) Minutes

func (j *Task) Minutes() *Task

Minutes set the unit with minute

func (*Task) Monday

func (j *Task) Monday() (job *Task)

Monday set the start day with Monday - s.Every(1).Monday().Do(task)

func (*Task) NextScheduledTime

func (j *Task) NextScheduledTime() time.Time

NextScheduledTime returns the time of when this job is to run next

func (*Task) Saturday

func (j *Task) Saturday() *Task

Saturday sets the job start day Saturday

func (*Task) Second

func (j *Task) Second() *Task

Second sets the unit with second

func (*Task) Seconds

func (j *Task) Seconds() *Task

Seconds set the unit with seconds

func (*Task) Sunday

func (j *Task) Sunday() *Task

Sunday sets the job start day Sunday

func (*Task) Tag

func (j *Task) Tag(t string, others ...string)

Tag allows you to add labels to a job they don't impact the functionality of the job.

func (*Task) Tags

func (j *Task) Tags() []string

Tags returns the tags attached to the job

func (*Task) Thursday

func (j *Task) Thursday() *Task

Thursday sets the job start day Thursday

func (*Task) Tuesday

func (j *Task) Tuesday() *Task

Tuesday sets the job start day Tuesday

func (*Task) Untag

func (j *Task) Untag(t string)

Untag removes a tag from a job

func (*Task) Wednesday

func (j *Task) Wednesday() *Task

Wednesday sets the job start day Wednesday

func (*Task) Week

func (j *Task) Week() *Task

Week sets the job's unit with week, which interval is 1

func (*Task) Weekday

func (j *Task) Weekday(startDay time.Weekday) *Task

Weekday start job on specific Weekday

func (*Task) Weeks

func (j *Task) Weeks() *Task

Weeks sets the units as weeks

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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