task

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTask

func AddTask(task *Task)

func Start

func Start()

启动计划监听,非阻塞启动

Types

type Handler

type Handler func()

type Manager

type Manager struct {
	//任务注册
	Tasks map[string]*Task
	//执行序列
	NextTime  time.Time
	NextTasks []*Task
}

func GetManager

func GetManager() *Manager

func (*Manager) Resort

func (m *Manager) Resort()

重新排序计算出下一个需要执行的计划任务

func (*Manager) Start

func (m *Manager) Start()

func (*Manager) Starts

func (m *Manager) Starts()

内部调用阻塞启动

type Task

type Task struct {
	Name    string
	Handler Handler
	Timer   *Timer
	LastRun time.Time
}

func NewTask

func NewTask(name string, handler Handler) *Task

创建一个新的任务,拥有默认的执行间隔,60秒

func (*Task) Add

func (t *Task) Add() *Task

func (*Task) GetTimer

func (t *Task) GetTimer() *Timer

func (*Task) SetAt

func (t *Task) SetAt(at *TimerAt) *Task

func (*Task) SetEvery

func (t *Task) SetEvery(every int) *Task

func (*Task) SetTimer

func (t *Task) SetTimer(timer *Timer)

type Timer

type Timer struct {
	Every int
	At    *TimerAt
}

func NewTimer

func NewTimer() *Timer

func (*Timer) GetNext

func (t *Timer) GetNext(now time.Time, lastRun time.Time) time.Time

func (*Timer) SetAt

func (t *Timer) SetAt(at *TimerAt) *Timer

func (*Timer) SetEvery

func (t *Timer) SetEvery(second int) *Timer

设置运行间隔

type TimerAt

type TimerAt struct {
	Second     []int //0-59
	SecondChan chan int
	SecondV    int
	Minute     []int //0-59
	MinuteChan chan int
	MinuteV    int
	Hour       []int //0-23
	HourChan   chan int
	HourV      int
	Day        []int //1-28-30-31
	DayChan    chan int
	DayV       int
	Week       []int //1-7
	WeekChan   chan int
	WeekV      int
	Month      []int //1-12
	MonthChan  chan int
	MonthV     int
	Year       []int //2022
	YearChan   chan int
	YearV      int
	Done       chan int
	Wg         *sync.WaitGroup
}

func NewAt

func NewAt() *TimerAt

func (*TimerAt) GetNextDay

func (at *TimerAt) GetNextDay(now time.Time)

func (*TimerAt) GetNextHour

func (at *TimerAt) GetNextHour(now time.Time)

func (*TimerAt) GetNextMinute

func (at *TimerAt) GetNextMinute(now time.Time)

func (*TimerAt) GetNextMonth

func (at *TimerAt) GetNextMonth(now time.Time)

func (*TimerAt) GetNextSecond

func (at *TimerAt) GetNextSecond(now time.Time, every int, lastRun time.Time)

func (*TimerAt) GetNextWeek

func (at *TimerAt) GetNextWeek(now time.Time)

func (*TimerAt) GetNextYear

func (at *TimerAt) GetNextYear(now time.Time)

func (*TimerAt) SetDay

func (at *TimerAt) SetDay(v ...int) *TimerAt

func (*TimerAt) SetHour

func (at *TimerAt) SetHour(v ...int) *TimerAt

func (*TimerAt) SetMinute

func (at *TimerAt) SetMinute(v ...int) *TimerAt

func (*TimerAt) SetMonth

func (at *TimerAt) SetMonth(v ...int) *TimerAt

func (*TimerAt) SetSecond

func (at *TimerAt) SetSecond(v ...int) *TimerAt

func (*TimerAt) SetWeek

func (at *TimerAt) SetWeek(v ...int) *TimerAt

func (*TimerAt) SetYear

func (at *TimerAt) SetYear(v ...int) *TimerAt

Jump to

Keyboard shortcuts

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