56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
|
package scheduler
|
||
|
|
||
|
import "time"
|
||
|
|
||
|
var defaultScheduler = NewScheduler()
|
||
|
|
||
|
// Schedule a new periodic job
|
||
|
func Every(interval uint64) Job {
|
||
|
return defaultScheduler.Every(interval)
|
||
|
}
|
||
|
|
||
|
// 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 RunPending() {
|
||
|
defaultScheduler.RunPending()
|
||
|
}
|
||
|
|
||
|
// Run all jobs regardless if they are scheduled to run or not.
|
||
|
func RunAll() {
|
||
|
defaultScheduler.RunAll()
|
||
|
}
|
||
|
|
||
|
// 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 RunAllwithDelay(d int) {
|
||
|
defaultScheduler.RunAllwithDelay(d)
|
||
|
}
|
||
|
|
||
|
// Run all jobs that are scheduled to run
|
||
|
func Start() chan bool {
|
||
|
return defaultScheduler.Start()
|
||
|
}
|
||
|
|
||
|
// Clear
|
||
|
func Clear() {
|
||
|
defaultScheduler.Clear()
|
||
|
}
|
||
|
|
||
|
// Remove
|
||
|
func Remove(j interface{}) {
|
||
|
defaultScheduler.Remove(j)
|
||
|
}
|
||
|
|
||
|
// NextRun gets the next running time
|
||
|
func NextRun() (job Job, time time.Time) {
|
||
|
return defaultScheduler.NextRun()
|
||
|
}
|