schedule

package
v0.0.0-...-df1a5a3 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2015 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidInterval  = errors.New("Interval must be greater than 0")
	ErrInvalidStartTime = errors.New("Start time is in the past")
	ErrInvalidStopTime  = errors.New("Stop time is in the past")
	ErrStopBeforeStart  = errors.New("Stop time cannot occur before start time")
)

Functions

This section is empty.

Types

type Response

type Response interface {
	// Contains any errors captured during a schedule.Wait()
	Error() error
	// Returns the schedule state
	State() ScheduleState
	// Returns any intervals that were missed since the call to Wait()
	Missed() uint
	// The time the interval fired
	LastTime() time.Time
}

type Schedule

type Schedule interface {
	// Returns the current state of the schedule
	GetState() ScheduleState
	// Returns where a schedule is still valid for this point in time.
	Validate() error
	// Blocks until time to fire and returns a schedule.Response
	Wait(time.Time) Response
}

type ScheduleState

type ScheduleState int
const (
	// set by the scheduler once a schedule has been validated and is in use in a task
	Active ScheduleState = iota
	// Schedule is ended
	Ended
	// Schedule is halted with an error
	Error
)

type SimpleSchedule

type SimpleSchedule struct {
	Interval time.Duration
	// contains filtered or unexported fields
}

A schedule that only implements an endless repeating interval

func NewSimpleSchedule

func NewSimpleSchedule(i time.Duration) *SimpleSchedule

func (*SimpleSchedule) GetState

func (s *SimpleSchedule) GetState() ScheduleState

func (*SimpleSchedule) Validate

func (s *SimpleSchedule) Validate() error

func (*SimpleSchedule) Wait

func (s *SimpleSchedule) Wait(last time.Time) Response

Waits until net interval and returns true. Returning false signals a Schedule is no longer valid and should be halted. A SimpleSchedule has no end and as long as start is not in the future we will always in practice return true.

type SimpleScheduleResponse

type SimpleScheduleResponse struct {
	// contains filtered or unexported fields
}

A response from SimpleSchedule conforming to ScheduleResponse interface

func (*SimpleScheduleResponse) Error

func (s *SimpleScheduleResponse) Error() error

Returns last error

func (*SimpleScheduleResponse) LastTime

func (s *SimpleScheduleResponse) LastTime() time.Time

func (*SimpleScheduleResponse) Missed

func (s *SimpleScheduleResponse) Missed() uint

Returns any missed intervals

func (*SimpleScheduleResponse) State

Returns the state of the Schedule

type WindowedSchedule

type WindowedSchedule struct {
	Interval  time.Duration
	StartTime *time.Time
	StopTime  *time.Time
	// contains filtered or unexported fields
}

A schedule that waits on an interval within a specific time window

func NewWindowedSchedule

func NewWindowedSchedule(i time.Duration, start *time.Time, stop *time.Time) *WindowedSchedule

func (*WindowedSchedule) GetState

func (w *WindowedSchedule) GetState() ScheduleState

func (*WindowedSchedule) Validate

func (w *WindowedSchedule) Validate() error

func (*WindowedSchedule) Wait

func (w *WindowedSchedule) Wait(last time.Time) Response

type WindowedScheduleResponse

type WindowedScheduleResponse struct {
	// contains filtered or unexported fields
}

A response from SimpleSchedule conforming to ScheduleResponse interface

func (*WindowedScheduleResponse) Error

func (w *WindowedScheduleResponse) Error() error

Returns last error

func (*WindowedScheduleResponse) LastTime

func (w *WindowedScheduleResponse) LastTime() time.Time

func (*WindowedScheduleResponse) Missed

func (w *WindowedScheduleResponse) Missed() uint

Returns any missed intervals

func (*WindowedScheduleResponse) State

Returns the state of the Schedule

Jump to

Keyboard shortcuts

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