Documentation ¶
Index ¶
- func ChangeTimeLocation(location *time.Location)
- func Clear()
- 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(jobFunction interface{}, params ...interface{}) error
- func (j *Job) DoJobSafely(jobFunction 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) GetAtTime() string
- func (j *Job) GetWeekday() time.Weekday
- func (j *Job) Hour() *Job
- func (j *Job) Hours() *Job
- func (j *Job) JobIsRunNow() bool
- func (j *Job) Location(location *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) Month() *Job
- func (j *Job) Months() *Job
- func (j *Job) MustInterval(i uint64) error
- func (j *Job) NextJobRun() error
- func (j *Job) NextScheduledTime() time.Time
- func (j *Job) PeriodDuration() (time.Duration, error)
- func (j *Job) RoundToMidNight(t time.Time) time.Time
- func (j *Job) Run() ([]reflect.Value, error)
- func (j *Job) Saturday() *Job
- func (j *Job) Second() *Job
- func (j *Job) Seconds() *Job
- func (j *Job) SetJobUnit(unit types.TimeUnit) *Job
- func (j *Job) Sunday() *Job
- func (j *Job) Tag(t string, others ...string)
- func (j *Job) TagList() []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) ChangeLocation(newLocation *time.Location)
- func (s *Scheduler) Clear()
- func (s *Scheduler) Every(interval uint64) *Job
- func (s *Scheduler) GetRunnableJobs() (runningJobs [types.MaxJobs]*Job, n int)
- 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) RemoveByCondition(remove func(*Job) bool)
- func (s *Scheduler) RemoveByRef(j *Job)
- func (s *Scheduler) RemoveByTag(t string)
- 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)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChangeTimeLocation ¶
ChangeTimeLocation change the location of a time
Types ¶
type Job ¶
type Job struct { JobFunction string Functions map[string]interface{} FuncParams map[string][]interface{} Interval uint64 JobUnit types.TimeUnit Tags []string AtTime time.Duration TimeLocation *time.Location LastRun time.Time NextRun time.Time FirstWeekDay time.Weekday JobError error LockJob bool }
Job information about a job
func (*Job) At ¶
At schedules the job to run at the given time
s.Every(1).Day().At("20:30:01").Do(task) s.Every(1).Monday().At("20:30:01").Do(task)
func (*Job) DoJobSafely ¶
DoJobSafely does the same thing as Do, except it logs unexpected panics rather than unwinding them up the chain
func (*Job) GetAtTime ¶
GetAtTime returns the time of day that the job will run s.Every(1).Day().At("20:30").GetAtTime() == "20:30"
func (*Job) GetWeekday ¶
GetWeekday this returns the day of the week that the job will run Only use this when .Weekday(...) is called on the job.
func (*Job) Location ¶
Location it set the location at which to interpret "At" s.Every(1).Day().At("20:30").Loc(time.UTC).Do(task)
func (*Job) MustInterval ¶
MustInterval set the job's unit with seconds,minutes,hours...
func (*Job) NextJobRun ¶
NextJobRun sets the next run time for the job
func (*Job) NextScheduledTime ¶
NextScheduledTime returns the next scheduled time of a job
func (*Job) PeriodDuration ¶
PeriodDuration returns the duration of the job
func (*Job) RoundToMidNight ¶
RoundToMidNight it set the job to run at the beginning of the next day
func (*Job) SetJobUnit ¶
SetJobUnit sets the JobUnit
type Scheduler ¶
type Scheduler struct { JobList [types.MaxJobs]*Job // Jobs is the array of jobs JobSize int // JobSize is the number of jobs Location *time.Location // Location is the location of the scheduler }
Scheduler is the main struct of the scheduler
func New ¶
func New() *Scheduler
New creates a new scheduler
Example ¶
greetingFunc := func() { fmt.Println("Hello, World!") } sched := New() if err := sched.Every(5).Second().Do(greetingFunc); err != nil { panic(err) } <-sched.Start()
Output:
func (*Scheduler) ChangeLocation ¶
ChangeLocation changes the default time location of the scheduler
func (*Scheduler) GetRunnableJobs ¶
GetRunnableJobs returns a list of jobs that are ready to run
func (*Scheduler) RemoveByCondition ¶
RemoveByCondition removes specific job j by condition
func (*Scheduler) RemoveByRef ¶
RemoveByRef removes specific job j by reference
func (*Scheduler) RemoveByTag ¶
RemoveByTag removes specific job j by tag
func (*Scheduler) RunAllWithDelay ¶
RunAllWithDelay runs all jobs with a delay