scheduler

package
v0.0.0-...-4e7898a Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close()

func Date

func Date() string

func DateStr

func DateStr(str string) string

func DiffMs

func DiffMs(pre, back int64) int64

func GetAge

func GetAge(birth string, parseStr string) int

GetAge 获取年龄

func GetDateStr

func GetDateStr(ts int64, day int, hour int) string

func GetDayBegin

func GetDayBegin(ts int64, day int, hour int) int64

n为-1时为当前时间0点,为0时为下一天的0点

GetDayBegin 获取指定hour时间戳

func GetDeltaDays

func GetDeltaDays(t1, t2 int64) int

func GetMondayUnix

func GetMondayUnix(hour int) int64

GetMondayUnix 获取当前时间周一的指定时间时间戳

func IsHoliday

func IsHoliday() bool

IsHoliday 是否是节假日

func IsToday

func IsToday(ts int64) bool

IsToday 是否是今日日期

func IsoCalendar

func IsoCalendar(nowTime int64) (year, week, weekday int)

IsoCalendar 日期

func Now

func Now() time.Time

func NowHour

func NowHour() int

func NowWeekDay

func NowWeekDay() time.Weekday

NowWeekDay 当前时间周几

func ParseTime

func ParseTime(str string) (time.Time, error)

func PushTask

func PushTask(task Task)

func Sched

func Sched()

func Unix

func Unix() int64

func UnixMs

func UnixMs() int64

func UnixNano

func UnixNano() int64

func UnixTime

func UnixTime(sec, nsec int64) time.Time

func YearMonth

func YearMonth() int

func YearMonthDay

func YearMonthDay() int

Types

type Hook

type Hook func()

type LocalScheduler

type LocalScheduler interface {
	Schedule(Task)
}

LocalScheduler schedules task to a customized goroutine

type Task

type Task func()

type Timer

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

Timer represents a cron job

func NewAfterTimer

func NewAfterTimer(duration time.Duration, fn TimerFunc) *Timer

NewAfterTimer returns a new Timer containing a function that will be called after duration that specified by the duration argument. The duration d must be greater than zero; if not, NewAfterTimer will panic. Stop the timer to release associated resources.

func NewCondTimer

func NewCondTimer(condition TimerCondition, fn TimerFunc) *Timer

NewCondTimer returns a new Timer containing a function that will be called when condition satisfied that specified by the condition argument. The duration d must be greater than zero; if not, NewCondTimer will panic. Stop the timer to release associated resources.

func NewCountTimer

func NewCountTimer(interval time.Duration, count int, fn TimerFunc) *Timer

NewCountTimer returns a new Timer containing a function that will be called with a period specified by the duration argument. After count times, timer will be stopped automatically, It adjusts the intervals for slow receivers. The duration d must be greater than zero; if not, NewCountTimer will panic. Stop the timer to release associated resources.

func NewTimer

func NewTimer(interval time.Duration, fn TimerFunc) *Timer

NewTimer returns a new Timer containing a function that will be called with a period specified by the duration argument. It adjusts the intervals for slow receivers. The duration d must be greater than zero; if not, NewTimer will panic. Stop the timer to release associated resources.

func (*Timer) ID

func (t *Timer) ID() int64

ID returns id of current timer

func (*Timer) Stop

func (t *Timer) Stop()

Stop turns off a timer. After Stop, fn will not be called forever

type TimerCondition

type TimerCondition interface {
	Check(now time.Time) bool
}

TimerCondition represents a checker that returns true when cron job needs to execute

type TimerFunc

type TimerFunc func()

TimerFunc represents a function which will be called periodically in main logic gorontine.

Jump to

Keyboard shortcuts

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