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 ¶
- Variables
- func ChangeLoc(newLocation *time.Location)
- func Clear()
- func Len() int
- func Remove(j interface{})
- func RunAll()
- func RunAllwithDelay(d int)
- func RunPending()
- 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) Err() error
- func (j *Job) Friday() *Job
- func (j *Job) Hour() *Job
- func (j *Job) Hours() *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) Thursday() *Job
- func (j *Job) Tuesday() *Job
- func (j *Job) Wednesday() *Job
- func (j *Job) Weekday(startDay time.Weekday) *Job
- func (j *Job) Weeks() *Job
- type Scheduler
- func (s *Scheduler) Clear()
- func (s *Scheduler) Err() error
- func (s *Scheduler) Every(interval uint64, options ...func(*Job)) *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) RunAll()
- func (s *Scheduler) RunAllwithDelay(d int)
- func (s *Scheduler) RunPending() error
- func (s *Scheduler) Start() chan bool
- func (s *Scheduler) Swap(i, j int)
Constants ¶
This section is empty.
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") )
globals
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 { ShouldDoImmediately bool // indicates that jobs should start before scheduling DistributedRedisClient *redis.Client // if the client is passed in the scheduler will check the redis client before running a job to corridinate with a distributed system DistributedJobName string // name assigned to the distributed job, if empty and more than one job is running a redis name collusion will occur // 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").Do(task) s.Every(1).Monday().At("10:30").Do(task)
func (*Job) NextScheduledTime ¶
NextScheduledTime returns the time of when this job is to run next
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) Err ¶
Err should be checked to ensure an error didn't occur durning the scheduling
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 ¶
RunPending runs all the jobs that are scheduled to run.