crons

package
v0.0.0-...-3534724 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Schedule

type Schedule struct {
	IsRecurring bool
	LastRun     time.Time
	NextRun     time.Time
	Interval    time.Duration
}

Schedule 保存任务执行时间相关的信息

type Scheduler

type Scheduler struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Scheduler 用于调度任务,它保存了待执行任务的相关信息

func NewScheduler

func NewScheduler() *Scheduler

NewScheduler 返回一个Scheduler结构体的实例

func (*Scheduler) Cancel

func (s *Scheduler) Cancel(uuid string) error

Cancel is used to cancel the planned execution of a specific task using it's ID. The ID is returned when the task was scheduled using RunAt, RunAfter or RunEvery

func (*Scheduler) Clear

func (s *Scheduler) Clear()

Clear 取消所有的调度任务

func (*Scheduler) Crons

func (s *Scheduler) Crons() (L []*models.Cron, err error)

Crons 返回队列中的任务列表,并转化成models.Cron

func (*Scheduler) RunAfter

func (s *Scheduler) RunAfter(duration time.Duration, name string, params ...string) (string, error)

RunAfter 等待一个指定的时间后执行一个任务

func (*Scheduler) RunAt

func (s *Scheduler) RunAt(when time.Time, name string, params ...string) (string, error)

RunAt 在一个给定时间执行一个任务

func (*Scheduler) RunEvery

func (s *Scheduler) RunEvery(interval time.Duration, name string, params ...string) (string, error)

RunEvery 给定周期,循环执行某一个任务

func (*Scheduler) Start

func (s *Scheduler) Start() error

Start 启动任务调度程序

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop will put the scheduler to halt

func (*Scheduler) Wait

func (s *Scheduler) Wait()

Wait is a convenience function for blocking until the scheduler is stopped.

type Task

type Task struct {
	Schedule
	Name      string
	UUID      string
	Cmd       string
	Status    string
	IsRunning bool
	Params    []string
	sync.Mutex
}

Task holds information about task

func NewTask

func NewTask(name, cmd string, params []string) *Task

NewTask returns an instance of task

func NewTaskWithSchedule

func NewTaskWithSchedule(name, cmd string, params []string, schedule Schedule) *Task

NewTaskWithSchedule creates an instance of task with the provided schedule information

func (*Task) IsDue

func (t *Task) IsDue() bool

IsDue returns a boolean indicating whether the task should execute or not

func (*Task) Run

func (t *Task) Run()

Run will execute the task and schedule it's next run.

func (*Task) ToCron

func (t *Task) ToCron() *models.Cron

ToCron 将task结构转成models.Cron

Jump to

Keyboard shortcuts

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