cherryTimer

package
v1.1.24 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LoopForever is a constant indicating that timer should loop forever
	LoopForever = -1
)

Variables

View Source
var (
	// Manager manager for all Timers
	Manager = &struct {
		incrementID    int64      // auto increment id
		timers         sync.Map   // all Timers
		ChClosingTimer chan int64 // timer for closing
		ChCreatedTimer chan *Timer
	}{}

	// Precision indicates the precision of timer, default is time.Second
	Precision = time.Second

	// GlobalTicker represents global ticker that all cron job will be executed
	// in globalTicker.
	GlobalTicker *time.Ticker
)

Functions

func AddTimer

func AddTimer(t *Timer)

AddTimer adds a timer to the manager

func Cron

func Cron()

Cron executes scheduled tasks TODO: if closing Timers'count in single cron call more than timerBacklog will case problem.

func RegisterComponent added in v1.1.24

func RegisterComponent()

func RemoveTimer

func RemoveTimer(id int64)

RemoveTimer removes a timer to the manager

func SetTimerBacklog

func SetTimerBacklog(c int)

SetTimerBacklog set the timer created/closing channel backlog, A small backlog may cause the logic to be blocked when call NewTimer/NewCountTimer/timer.OnStop in main logic gorontine.

Types

type Component

type Component struct {
	cherryFacade.Component
	// contains filtered or unexported fields
}

func NewComponent

func NewComponent() *Component

func (*Component) Init

func (p *Component) Init()

func (*Component) Name

func (p *Component) Name() string

func (*Component) OnBeforeStop

func (p *Component) OnBeforeStop()

func (*Component) OnStop

func (p *Component) OnStop()

type Condition

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

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

type Func

type Func func()

Func represents a function which will be called periodically in main logic goroutine.

type Timer

type Timer struct {
	ID int64 // timer id
	// contains filtered or unexported fields
}

Timer represents a cron job

func NewCounterTimer

func NewCounterTimer(fn Func, interval, delay time.Duration, counter int) *Timer

NewCounterTimer creates a cron job

func NewEveryDayTimer

func NewEveryDayTimer(fn Func, hour, minutes, seconds int) *Timer

NewEveryDayTimer 每天的x分x秒执行一次(每天1次)

func NewEveryHourTimer

func NewEveryHourTimer(fn Func, minute, second int) *Timer

NewEveryHourTimer 每小时的x分x秒执行一次(每天24次)

func NewTimer

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

NewTimer creates a loop forever cron job

func (*Timer) SetCondition

func (t *Timer) SetCondition(condition Condition)

SetCondition sets the condition used for verifying when the cron job should run

func (*Timer) Stop

func (t *Timer) Stop()

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

Jump to

Keyboard shortcuts

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