schedule

package
Version: v0.12.0-beta Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2016 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidInterval - Error message for the valid schedule interval must ne greater than 0
	ErrInvalidInterval = errors.New("Interval must be greater than 0")
	// ErrInvalidStartTime - Error message for the start time is in the past
	ErrInvalidStartTime = errors.New("Start time is in the past")
	// ErrInvalidStopTime - Error message for the stop tome is in the past
	ErrInvalidStopTime = errors.New("Stop time is in the past")
	// ErrStopBeforeStart - Error message for the stop time cannot occur before start time
	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
}

Response interface defines the behavior of schedule response

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
}

Schedule interface

type ScheduleState

type ScheduleState int

ScheduleState int type

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

type SimpleSchedule

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

SimpleSchedule is a schedule that only implements an endless repeating interval

func NewSimpleSchedule

func NewSimpleSchedule(i time.Duration) *SimpleSchedule

NewSimpleSchedule returns the SimpleSchedule given the time interval

func (*SimpleSchedule) GetState

func (s *SimpleSchedule) GetState() ScheduleState

GetState returns the schedule state

func (*SimpleSchedule) Validate

func (s *SimpleSchedule) Validate() error

Validate returns an error if the interval of schedule is less or equals zero

func (*SimpleSchedule) Wait

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

Wait returns the SimpleSchedule state, misses and the last schedule ran

type SimpleScheduleResponse

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

SimpleScheduleResponse a response from SimpleSchedule conforming to ScheduleResponse interface

func (*SimpleScheduleResponse) Error

func (s *SimpleScheduleResponse) Error() error

Error returns last error

func (*SimpleScheduleResponse) LastTime

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

LastTime retruns the last response time

func (*SimpleScheduleResponse) Missed

func (s *SimpleScheduleResponse) Missed() uint

Missed returns any missed intervals

func (*SimpleScheduleResponse) State

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
}

WindowedSchedule is 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

NewWindowedSchedule returns an instance of WindowedSchedule given duration, start and stop time

func (*WindowedSchedule) GetState

func (w *WindowedSchedule) GetState() ScheduleState

GetState returns ScheduleState of WindowedSchedule

func (*WindowedSchedule) Validate

func (w *WindowedSchedule) Validate() error

Validate validates the start, stop and duration interval of WindowedSchedule

func (*WindowedSchedule) Wait

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

Wait waits the window interval and return. Otherwise, it exits with a completed state

type WindowedScheduleResponse

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

WindowedScheduleResponse is the response from SimpleSchedule conforming to ScheduleResponse interface

func (*WindowedScheduleResponse) Error

func (w *WindowedScheduleResponse) Error() error

Error returns last error

func (*WindowedScheduleResponse) LastTime

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

LastTime returns the last windowed schedule response time

func (*WindowedScheduleResponse) Missed

func (w *WindowedScheduleResponse) Missed() uint

Missed returns any missed intervals

func (*WindowedScheduleResponse) State

State returns the state of the Schedule

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL