Documentation ¶
Overview ¶
Package gocron : A Golang Job Scheduling Package.
An in-process scheduler for periodic jobs that uses the builder pattern for configuration. Schedule lets you run Golang functions periodically at pre-determined intervals using a simple, human-friendly syntax.
Inspired by the Ruby module clockwork <https://github.com/tomykaira/clockwork> and Python package schedule <https://github.com/dbader/schedule>
See also http://adam.heroku.com/past/2010/4/13/rethinking_cron/ http://adam.heroku.com/past/2010/6/30/replace_cron_with_clockwork/
Copyright 2014 Jason Lyu. jasonlvhit@gmail.com . All rights reserved. Use of this source code is governed by a BSD-style . license that can be found in the LICENSE file.
Index ¶
- Constants
- Variables
- func ChangeLoc(newLocation *time.Location)
- func Clear()
- func NextTick() *time.Time
- func Remove(j interface{})
- func RunAll()
- func RunAllwithDelay(d int)
- func RunPending()
- func Scheduled(j interface{}) bool
- func SetLocker(l Locker)
- func Start() chan bool
- type Job
- func (j *Job) At(t string) *Job
- func (j *Job) Day() *Job
- func (j *Job) Days() *Job
- func (j *Job) Do(jobFun interface{}, params ...interface{}) error
- func (j *Job) DoSafely(jobFun interface{}, params ...interface{}) error
- func (j *Job) Err() error
- func (j *Job) Friday() *Job
- func (j *Job) From(t *time.Time) *Job
- func (j *Job) GetAt() string
- func (j *Job) GetWeekday() time.Weekday
- func (j *Job) Hour() *Job
- func (j *Job) Hours() *Job
- func (j *Job) Loc(loc *time.Location) *Job
- func (j *Job) Lock() *Job
- func (j *Job) Minute() *Job
- func (j *Job) Minutes() *Job
- func (j *Job) Monday() (job *Job)
- func (j *Job) NextScheduledTime() time.Time
- func (j *Job) Saturday() *Job
- func (j *Job) Second() *Job
- func (j *Job) Seconds() *Job
- func (j *Job) Sunday() *Job
- func (j *Job) Tag(t string, others ...string)
- func (j *Job) Tags() []string
- func (j *Job) Thursday() *Job
- func (j *Job) Tuesday() *Job
- func (j *Job) Untag(t string)
- func (j *Job) Wednesday() *Job
- func (j *Job) Week() *Job
- func (j *Job) Weekday(startDay time.Weekday) *Job
- func (j *Job) Weeks() *Job
- type Locker
- type Scheduler
- func (s *Scheduler) ChangeLoc(newLocation *time.Location)
- func (s *Scheduler) Clear()
- func (s *Scheduler) Every(interval uint64) *Job
- func (s *Scheduler) Jobs() []*Job
- func (s *Scheduler) Len() int
- func (s *Scheduler) Less(i, j int) bool
- func (s *Scheduler) NextRun() (*Job, time.Time)
- func (s *Scheduler) Remove(j interface{})
- func (s *Scheduler) RemoveByRef(j *Job)
- func (s *Scheduler) RunAll()
- func (s *Scheduler) RunAllwithDelay(d int)
- func (s *Scheduler) RunPending()
- func (s *Scheduler) Scheduled(j interface{}) bool
- func (s *Scheduler) Start() chan bool
- func (s *Scheduler) Swap(i, j int)
Constants ¶
const MAXJOBNUM = 10000
MAXJOBNUM max number of jobs, hack it if you need.
Variables ¶
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 paramaters cannot be used with reflection") )
Functions ¶
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.
Types ¶
type Job ¶
type Job struct {
// contains filtered or unexported fields
}
Job struct keeping information about job
func (*Job) At ¶
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 (*Job) DoSafely ¶
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 (*Job) GetAt ¶
GetAt returns the specific time of day the job will run at
s.Every(1).Day().At("10:30").GetAt() == "10:30"
func (*Job) GetWeekday ¶
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 (*Job) Loc ¶
Loc sets the location for which to interpret "At"
s.Every(1).Day().At("10:30").Loc(time.UTC).Do(task)
func (*Job) NextScheduledTime ¶
NextScheduledTime returns the time of when this job is to run next
func (*Job) Tag ¶
Tag allows you to add labels to a job they don't impact the functionality of the job.
type Locker ¶
Locker provides a method to lock jobs from running at the same time on multiple instances of gocron. You can provide any locker implementation you wish.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler struct, the only data member is the list of jobs. - implements the sort.Interface{} for sorting jobs, by the time nextRun
func (*Scheduler) Remove ¶
func (s *Scheduler) Remove(j interface{})
Remove specific job j by function
func (*Scheduler) RemoveByRef ¶
RemoveByRef removes specific job j by reference
func (*Scheduler) RunAll ¶
func (s *Scheduler) RunAll()
RunAll run all jobs regardless if they are scheduled to run or not
func (*Scheduler) RunAllwithDelay ¶
RunAllwithDelay runs all jobs with delay seconds
func (*Scheduler) RunPending ¶
func (s *Scheduler) RunPending()
RunPending runs all the jobs that are scheduled to run.