scheduler

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 JobFunc

type JobFunc func(from, to time.Time, interval time.Duration) (interface{}, error)

JobFunc is a function implementing the Job interface

func (JobFunc) Run

func (job JobFunc) Run(from, to time.Time, interval time.Duration) (interface{}, error)

Run the job by calling the function

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

func NewScheduler(name string, job Job, defaultInterval time.Duration) *Scheduler

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

func (sched *Scheduler) Ack() error

Ack acknowledges the last run. It does nothing if last run did not succeed, or has already been aknowledged

func (*Scheduler) GetInterval

func (sched *Scheduler) GetInterval() time.Duration

GetInterval returns the scheduled interval set, or the default one

func (*Scheduler) Name

func (sched *Scheduler) Name() string

Name returns the name of this scheduler

func (*Scheduler) NextRun

func (sched *Scheduler) NextRun() time.Time

NextRun returns the time of the next run

func (*Scheduler) Ready

func (sched *Scheduler) Ready() bool

Ready returns true if it's time for the next run

func (*Scheduler) SetInterval

func (sched *Scheduler) SetInterval(interval time.Duration) error

SetInterval modifies the scheduled interval

func (*Scheduler) Step

func (sched *Scheduler) Step() (interface{}, error)

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

func (sched *Scheduler) StepWait() (interface{}, error)

StepWait execute the next round, waiting for the proper time if it's necessary

func (*Scheduler) Wait

func (sched *Scheduler) Wait(ctx context.Context) error

Wait the necessary time before the next run becomes possible

func (*Scheduler) WaitChan

func (sched *Scheduler) WaitChan() *time.Timer

WaitChan returns a timer.Timer set to wait for the next run

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL