schedule

package
v0.16.1-beta Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2016 License: Apache-2.0 Imports: 4 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")
	// 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")
)
View Source
var ErrMissingCronEntry = errors.New("Cron entry is missing")

ErrMissingCronEntry indicates missing cron entry

Functions

This section is empty.

Types

type CronSchedule

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

CronSchedule is a schedule that waits as long as specified in cron entry

func NewCronSchedule

func NewCronSchedule(entry string) *CronSchedule

NewCronSchedule creates and starts new cron schedule and returns an instance of CronSchedule

func (*CronSchedule) Entry

func (c *CronSchedule) Entry() string

Entry returns the cron schedule entry

func (*CronSchedule) GetState

func (c *CronSchedule) GetState() ScheduleState

GetState returns state of CronSchedule

func (*CronSchedule) Validate

func (c *CronSchedule) Validate() error

Validate returns error if cron entry dosn't match crontab format

func (*CronSchedule) Wait

func (c *CronSchedule) Wait(last time.Time) Response

Wait waits as long as specified in cron entry

type CronScheduleResponse

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

CronScheduleResponse is the response from CronSchedule

func (*CronScheduleResponse) Error

func (c *CronScheduleResponse) Error() error

Error returns last error

func (*CronScheduleResponse) LastTime

func (c *CronScheduleResponse) LastTime() time.Time

LastTime returns the last response time

func (*CronScheduleResponse) Missed

func (c *CronScheduleResponse) Missed() uint

Missed returns any missed intervals

func (*CronScheduleResponse) State

State returns the state of the Schedule

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
y or Y : Canonical URL