scheduler

package
v0.5.22 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SchedulerIdle = iota
	SchedulerRunning
	SchedulerShutdown
	SchedulerStopped
)

Variables

View Source
var (
	ErrInvalidParameter    = errors.New("invalid parameter")
	ErrSchedulerNotRunning = errors.New("scheduler not running")
	ErrJobHastenCanceled   = errors.New("job has been canceled")
)

Functions

This section is empty.

Types

type ITimer

type ITimer interface {
	Init(...Option) error
	// Start the scheduler manager and initialize it according to the preset configuration
	Start() error
	// IsRunning will return the status of scheduler
	IsRunning() bool
	// Tick main loop
	Tick()
	// AddTimer will add a scheduled task that is executed periodically and stops immediately if an error occurs during execution
	AddTimer(TimerFunc, time.Duration, ...TaskOption) (TimerHandler, error)
	// AddTimerOnce will add a scheduled task that triggers execution at a specified time.
	AddTimerOnce(TimerFunc, time.Duration, ...TaskOption) (TimerHandler, error)
	//AddTimerWithCount will add a scheduled task and execute it periodically at the specified interval.
	//When a specified number of times is reached or an error occurs, the task is stopped
	AddTimerWithCount(TimerFunc, time.Duration, int, ...TaskOption) (TimerHandler, error)
	// Corn will set a scheduled task to be automatically executed at a specified time
	// which follows https://en.wikipedia.org/wiki/Cron
	Corn(TimerFunc, string, ...TaskOption) (TimerHandler, error)
	// CancelTimer will stop a scheduled task
	CancelTimer(TimerHandler) error
	// Count will return the number of tasks on the timer
	Count() int
	// Shutdown will stop all tasks, and remove them from scheduler
	Shutdown() error
}

func NewScheduler

func NewScheduler() (ITimer, error)

type Option

type Option func(options *Options)

Option 定时器配置修改函数原型

func WithMaxJobCount

func WithMaxJobCount(count int) Option

type Options

type Options struct {
	Location          *time.Location `yaml:"location"`            // 定时器时区,
	MaxConcurrentJobs int            `yaml:"max_concurrent_jobs"` // 最大定时任务数量
}

Options is the scheduler config

func NewOptions

func NewOptions() *Options

type TaskOption

type TaskOption func(options *TaskOptions)

TaskOption 定时任务配置修改函数原型

func WithCountTask

func WithCountTask(count int) TaskOption

func WithImmediatelyTask

func WithImmediatelyTask(immediately bool) TaskOption

func WithSingleModeTask

func WithSingleModeTask(singleMode int) TaskOption

func WithTagTask

func WithTagTask(tag string) TaskOption

type TaskOptions

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

TaskOptions 定时任务配置

func NewTaskOptions

func NewTaskOptions() *TaskOptions

type TimerFunc

type TimerFunc func() error // 定时器函数

type TimerHandleGenerator

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

func (*TimerHandleGenerator) Init

func (t *TimerHandleGenerator) Init() error

func (*TimerHandleGenerator) Next

Next 产生进程内唯一id, 算法:当前秒数的时间戳 + 一秒内调用次数

func (*TimerHandleGenerator) Tick

func (t *TimerHandleGenerator) Tick()

Tick 检测时间戳更新, 每秒重置一次

type TimerHandler

type TimerHandler uint64 // 定时器句柄

Jump to

Keyboard shortcuts

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