timermanager

package
v0.0.0-...-cc86db0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AtExpressionPrefix = "at("
)
View Source
const (
	RateExpressionPrefix = "rate("
)

Variables

View Source
var (
	ErrInvalidAtExpression = newCronParameterError("InvalidAtExpression", "invalid at expression cannot be parsed")
	ErrAtExpressionExpired = newCronParameterError("AtExpressionExpired", "at expression had expired at the moment of system clock")
)
View Source
var (
	CronYearFieldRegexp = regexp.MustCompile(`^\*$|^\?$|19[789][0-9]|20[0-9]{2}|^\*/(\d+)$`)
	// GMT+13:00/GMT+14:00 do exist, even GMT+13:45. But GMT-13:**/GMT-14:00 do not.
	GMTOffsetTimezoneRegexp = regexp.MustCompile(`GMT([+-])([0-9]|1[0-4]):([0-5][0-9])`)

	ErrInvalidCronExpression             = newCronParameterError("InvalidCronExpression", "invalid cron expression cannot be parsed")
	ErrTimezoneInformationCorrupt        = newCronParameterError("TimezoneInformationCorrupt", "Information of sepcified timezone in cron expression cannot be parsed")
	ErrInvalidGMTOffsetForTimezone       = newCronParameterError("InvalidGMTOffsetForTimezone", "invalid GMT+-offset format at timezone field cannot be parsed")
	ErrInvalidGMTOffsetHourForTimezone   = newCronParameterError("InvalidGMTOffsetHourForTimezone", "invalid hour value for GMT+-offset format at timezone field cannot be parsed")
	ErrInvalidGMTOffsetMinuteForTimezone = newCronParameterError("InvalidGMTOffsetMinuteForTimezone", "invalid minute value for GMT+-offset format at timezone field cannot be parsed")
	ErrCronExpressionExpired             = newCronParameterError("CronExpressionExpired", "cron expression had expired at the moment of system clock")
)
View Source
var (
	ErrInvalidRateExpression = newCronParameterError("InvalidRateExpression", "invalid rate expression cannot be parsed")
	ErrRateFrequencyTooLarge = newCronParameterError("RateFrequencyTooLarge", "specified frequency in rate expression is too large, i.e., larger than 1,000 days")
)
View Source
var (
	ErrNoNextRun = errors.New("Schedule has finished and no next run")
)

Functions

func InitTimerManager

func InitTimerManager() error

InitTimerManager explicitly initialize global TimerManager instance, which should be invoked before all timer creation behaviors.

Types

type AtScheduled

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

func NewAtScheduled

func NewAtScheduled(cronat string) (*AtScheduled, error)

NewAtScheduled returns scheduler from at expression

func (*AtScheduled) NextRunFrom

func (a *AtScheduled) NextRunFrom(t time.Time) (time.Duration, error)

type CronParameterError

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

func (*CronParameterError) Code

func (e *CronParameterError) Code() string

func (CronParameterError) Error

func (e CronParameterError) Error() string

func (*CronParameterError) Message

func (e *CronParameterError) Message() string

type CronScheduled

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

CronScheduled provides nextRun() interface for cron expression

func NewCronScheduled

func NewCronScheduled(cronat string) (*CronScheduled, error)

NewCronScheduled returns scheduler from cron expression

Classic style and new styles of cron expression are both supported: * Classic: `Seconds Minutes Hours Day_of_month Month Day_of_week` * New: `Seconds Minutes Hours Day_of_month Month Day_of_week Year(optional) Timezone(optional)`

For timezone specification, two formats are supported: * Complete name in TZ database, e.g., Asia/Shanghai, America/Los_Angeles * GMT offset (no leading zero in hour), e.g., GMT+8:00, GMT-6:00 * Some fixed and unambiguous abbreviation names of timezone, namely:

  • GMT
  • UTC

func (*CronScheduled) Location

func (c *CronScheduled) Location() *time.Location

func (*CronScheduled) NextRunFrom

func (c *CronScheduled) NextRunFrom(t time.Time) (time.Duration, error)

func (*CronScheduled) NoNextRun

func (c *CronScheduled) NoNextRun() bool

type MutableScheduled

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

func NewMutableScheduled

func NewMutableScheduled(interval time.Duration) *MutableScheduled

func (*MutableScheduled) NotImmediately

func (m *MutableScheduled) NotImmediately() *MutableScheduled

func (*MutableScheduled) SetInterval

func (m *MutableScheduled) SetInterval(newInterval time.Duration) *MutableScheduled

type RateScheduled

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

func NewRateScheduled

func NewRateScheduled(cronat string, startTime time.Time) (*RateScheduled, error)

NewRateScheduled returns scheduler from rate() expression

func (*RateScheduled) NextRunFrom

func (r *RateScheduled) NextRunFrom(t time.Time) (time.Duration, error)

type Timer

type Timer struct {
	Schedule scheduled
	// contains filtered or unexported fields
}

func NewTimer

func NewTimer(s scheduled, c TimerCallback) *Timer

func (*Timer) IsRunning

func (t *Timer) IsRunning() bool

func (*Timer) RefreshTimer

func (t *Timer) RefreshTimer()

func (*Timer) Run

func (t *Timer) Run() (*Timer, error)

func (*Timer) SkipWaiting

func (t *Timer) SkipWaiting()

func (*Timer) Stop

func (t *Timer) Stop()

type TimerCallback

type TimerCallback func()

type TimerManager

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

func GetTimerManager

func GetTimerManager() *TimerManager

GetTimerManager just returns pointer to global TimerManager instance. Do not forget to check whether it is nil before using.

func (*TimerManager) CreateAtTimer

func (m *TimerManager) CreateAtTimer(callback TimerCallback, cronat string) (*Timer, error)

func (*TimerManager) CreateCronTimer

func (m *TimerManager) CreateCronTimer(callback TimerCallback, cronat string) (*Timer, error)

func (*TimerManager) CreateRateTimer

func (m *TimerManager) CreateRateTimer(callback TimerCallback, cronat string, creationTime time.Time) (*Timer, error)

func (*TimerManager) CreateTimerInNanoseconds

func (m *TimerManager) CreateTimerInNanoseconds(callback TimerCallback, interval time.Duration) (*Timer, error)

CreateTimerInNanoseconds returns new registered timer in precision of nanoseconds

func (*TimerManager) CreateTimerInSeconds

func (m *TimerManager) CreateTimerInSeconds(callback TimerCallback, seconds int) (*Timer, error)

CreateTimerInSeconds returns new registered timer in precision of seconds

func (*TimerManager) DeleteTimer

func (m *TimerManager) DeleteTimer(t *Timer)

func (*TimerManager) Start

func (m *TimerManager) Start()

func (*TimerManager) Stop

func (m *TimerManager) Stop()

Jump to

Keyboard shortcuts

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