Documentation ¶
Index ¶
- Variables
- type Job
- type JobFunc
- type Scheduler
- func (sched *Scheduler) Ack() error
- func (sched *Scheduler) GetInterval() time.Duration
- func (sched *Scheduler) Name() string
- func (sched *Scheduler) NextRun() time.Time
- func (sched *Scheduler) Ready() bool
- func (sched *Scheduler) SetInterval(interval time.Duration) error
- func (sched *Scheduler) Step() (interface{}, error)
- func (sched *Scheduler) StepWait() (interface{}, error)
- func (sched *Scheduler) Wait(ctx context.Context) error
- func (sched *Scheduler) WaitChan() *time.Timer
- type State
Constants ¶
This section is empty.
Variables ¶
var ErrNotReady = errors.New("Scheduler not ready")
ErrNotReady is the error returned when the scheduler is not ready meaning it's not the time yet to run
Functions ¶
This section is empty.
Types ¶
type Job ¶
type Job interface { // Run the job, providing it with timing information Run(from, to time.Time, interval time.Duration) (interface{}, error) }
Job is an interface to a schedulable task
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler schedules a job on a periodic interval. It provides on each Job run some timing information about the interval being invoked. After a run, the scheduler must receive Akcnowledge to commit the interval
WARNING: The Scheduler is not thread safe and must not be used as is (without additional care) from multiple goroutines
func NewScheduler ¶
NewScheduler creates a new scheduler with the given Job, and default interval. Scheduler internal state is handled in memory
func NewSchedulerWithState ¶
func NewSchedulerWithState(name string, job Job, defaultInterval time.Duration, state State) *Scheduler
NewSchedulerWithState creates a new scheduler with the given Job, default interval, using the procided internal state handler
func (*Scheduler) Ack ¶
Ack acknowledges the last run. It does nothing if last run did not succeed, or has already been aknowledged
func (*Scheduler) GetInterval ¶
GetInterval returns the scheduled interval set, or the default one
func (*Scheduler) SetInterval ¶
SetInterval modifies the scheduled interval
func (*Scheduler) Step ¶
Step will execute the next round, starting from the last Acknowledged run
It won't wait until it's time to be run. If it's not the time, it will return an error. For a blocking alternative, see StepWait()
func (*Scheduler) StepWait ¶
StepWait execute the next round, waiting for the proper time if it's necessary
type State ¶
type State interface { // NextRun returns the time at which next execution should occure NextRun(name string) time.Time // UpdateNextRun set the time of the next execution UpdateNextRun(name string, next time.Time) error // Interval returns the scheduler exceution interval Interval(name string) time.Duration // UpdateInterval set a new execution interval for the scheduler UpdateInterval(name string, interval time.Duration) error // UpdateScheduler set both interval and next execution time for the scheduler UpdateScheduler(name string, interval time.Duration, next time.Time) error }
State handles schedulers internal state