定时cron类

package
v0.0.0-...-7e18bce Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

gcron 包实现了cron模式解析器和任务运行器。 md5:56d461ee2c75e1f7

Index

Constants

View Source
const (
	StatusReady   = gtimer.StatusReady
	StatusRunning = gtimer.StatusRunning
	StatusStopped = gtimer.StatusStopped
	StatusClosed  = gtimer.StatusClosed
)

Variables

This section is empty.

Functions

func DelayAdd

func DelayAdd(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)

DelayAdd 在延迟'delay'时间后,向默认的cron对象添加一个定时任务。 md5:7c28aadbf64d1362

func DelayAddOnce

func DelayAddOnce(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)

DelayAddOnce 在 `delay` 时间后向默认cron对象添加一个定时任务。 这个定时任务只能运行一次。 md5:56e7e748e4d4c63d

func DelayAddSingleton

func DelayAddSingleton(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)

DelayAddSingleton 在默认的cron对象中延迟`delay`时间后添加一个单例定时任务。 md5:d6c26c1edc16c19a

func DelayAddTimes

func DelayAddTimes(ctx context.Context, delay time.Duration, pattern string, times int, job JobFunc, name ...string)

DelayAddTimes 在`delay`时间后向默认cron对象添加一个定时任务。这个定时任务可以运行指定次数。 md5:b4ecf68ee4e86408

func GetLogger

func GetLogger() glog.ILogger

GetLogger 返回 cron 中的全局日志记录器。 md5:908af8c408f25d3d

func Remove

func Remove(name string)

Remove 删除名为`name`的计划任务。 md5:bc96b6bdb0bac57b

func SetLogger

func SetLogger(logger glog.ILogger)

SetLogger 设置 cron 的全局日志记录器。 md5:b0a9c7514a8c8b29

func Size

func Size() int

Size 返回默认cron中定时任务的数量。 md5:e87d680e31031739

func Start

func Start(name ...string)

Start 启动指定名为 `name` 的定时任务。如果没有指定 `name`,则启动整个 cron。 md5:d573745c6d8edaac

func Stop

func Stop(name ...string)

Stop 停止运行指定的定时任务,任务名为 `name`。如果未指定 `name`,则停止整个cron(cron job)。 md5:68ed27359d633f5e

Types

type Cron

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

Cron 存储所有的cron作业项。 md5:3a72b04261d69d0e

func New

func New() *Cron

New 返回一个具有默认设置的新 Cron 对象。 md5:d0ca0545e6ef9b46

func (*Cron) Add

func (c *Cron) Add(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)

Add 添加一个定时任务。 一个唯一的`name`可以与定时任务绑定。 如果`name`已经被使用,它将返回一个错误。 md5:850ebd654a2e3695

func (*Cron) AddEntry

func (c *Cron) AddEntry(
	ctx context.Context,
	pattern string,
	job JobFunc,
	times int,
	isSingleton bool,
	name ...string,
) (*Entry, error)

AddEntry 创建并返回一个新的 Entry 对象。 md5:1a7d5709c2867437

func (*Cron) AddOnce

func (c *Cron) AddOnce(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)

AddOnce 添加一个定时任务,该任务只能运行一次。 可以为定时任务绑定一个唯一的`name`。 如果`name`已使用,将返回一个错误。 md5:fd5fb4f131e1f937

func (*Cron) AddSingleton

func (c *Cron) AddSingleton(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)

AddSingleton 添加一个单例定时任务。 单例定时任务是指在同一时间只能运行一个实例的任务。 可以通过一个唯一的`name`与定时任务绑定。 如果`name`已经被使用,它将返回错误。 md5:9e0e86c2aee09877

func (*Cron) AddTimes

func (c *Cron) AddTimes(ctx context.Context, pattern string, times int, job JobFunc, name ...string) (*Entry, error)

AddTimes 添加一个定时任务,可以指定执行次数。 可以为定时任务绑定一个唯一的`name`。 如果`name`已存在,将返回一个错误。 md5:b01e5695f9cc54d5

func (*Cron) Close

func (c *Cron) Close()

Close 停止并关闭当前的cron。 md5:95a4276ef94fb50c

func (*Cron) DelayAdd

func (c *Cron) DelayAdd(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)

DelayAdd 在`delay`时间后添加一个定时任务。 md5:027e39a4b8e3b167

func (*Cron) DelayAddEntry

func (c *Cron) DelayAddEntry(ctx context.Context, delay time.Duration, pattern string, job JobFunc, times int, isSingleton bool, name ...string)

DelayAddEntry 在延迟`delay`时间后添加一个定时任务。 md5:a45391b1d2daacd5

func (*Cron) DelayAddOnce

func (c *Cron) DelayAddOnce(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)

DelayAddOnce 在 `delay` 时间后添加一个定时任务。 这个定时任务只能运行一次。 md5:34aa0df8fb8e5477

func (*Cron) DelayAddSingleton

func (c *Cron) DelayAddSingleton(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)

DelayAddSingleton 在`delay`时间后添加一个单例计时任务。 md5:c56847cf6733a3e4

func (*Cron) DelayAddTimes

func (c *Cron) DelayAddTimes(ctx context.Context, delay time.Duration, pattern string, times int, job JobFunc, name ...string)

DelayAddTimes 在延迟`delay`时间后添加一个定时任务。 该定时任务可以指定运行次数。 md5:5ed58fb7650ed0bb

func (*Cron) Entries

func (c *Cron) Entries() []*Entry

Entries 返回所有定时任务作为切片(按注册时间升序排列)。 md5:67b4f559a25d411e

func (*Cron) GetLogger

func (c *Cron) GetLogger() glog.ILogger

GetLogger 在cron中返回日志记录器。 md5:014719534223048e

func (*Cron) Remove

func (c *Cron) Remove(name string)

Remove 删除名为`name`的计划任务。 md5:bc96b6bdb0bac57b

func (*Cron) Search

func (c *Cron) Search(name string) *Entry

Search 返回指定名称的计划任务。 如果未找到,则返回 nil。 md5:b0da4b1e1203c6c7

func (*Cron) SetLogger

func (c *Cron) SetLogger(logger glog.ILogger)

SetLogger 为 cron 设置日志记录器。 md5:87e9222eac80e2a1

func (*Cron) Size

func (c *Cron) Size() int

Size返回定时任务的大小。 md5:a282381f7ca9bf53

func (*Cron) Start

func (c *Cron) Start(name ...string)

Start 启动指定名为 `name` 的定时任务。如果没有指定 `name`,则启动整个 cron。 md5:d573745c6d8edaac

func (*Cron) Stop

func (c *Cron) Stop(name ...string)

Stop 停止运行指定的定时任务,任务名为 `name`。如果未指定 `name`,则停止整个cron(cron job)。 md5:68ed27359d633f5e

type Entry

type Entry struct {
	Name         string    // Entry name.
	RegisterTime time.Time // Registered time.
	Job          JobFunc   `json:"-"` // Callback function.
	// contains filtered or unexported fields
}

Entry 是定时任务的入口。 md5:ebc0ffec0c819fa5

func Add

func Add(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)

Add 向默认的 cron 对象添加一个定时任务。 一个唯一的 `name` 可以与定时任务绑定。 如果 `name` 已经被使用,它将返回一个错误。 md5:0f46b08a5a96144a

func AddOnce

func AddOnce(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)

AddOnce 向默认cron对象添加一个仅能运行一次的定时任务。可以为定时任务绑定一个唯一的`name`。 如果`name`已存在,它将返回一个错误。 md5:9701998ce952852d

func AddSingleton

func AddSingleton(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)

AddSingleton 向默认的 cron 对象添加一个单例定时任务。 单例定时任务是指在同一时间只能运行一个实例的任务。 可以将一个唯一的 `name` 与定时任务绑定。 如果 `name` 已经被使用,它将返回错误。 md5:96268d3e8373359e

func AddTimes

func AddTimes(ctx context.Context, pattern string, times int, job JobFunc, name ...string) (*Entry, error)

AddTimes 将一个定时任务添加到默认cron对象中,该任务可以执行指定次数。可以为定时任务绑定一个唯一的`name`。 如果`name`已经存在,它将返回一个错误。 md5:505a2bbf10529705

func Entries

func Entries() []*Entry

Entries 返回所有定时任务作为切片。 md5:16823f1ebafbd9cc

func Search(name string) *Entry

Search 返回具有指定`name`的计划任务。 如果未找到,返回nil。 md5:06da84fc0766d888

func (*Entry) Close

func (e *Entry) Close()

Close 停止并从 cron 中移除条目。 md5:a2a5eee9228cd918

func (*Entry) IsSingleton

func (e *Entry) IsSingleton() bool

IsSingleton 判断这个条目是否是定时单例任务。 md5:171967c731b60f88

func (*Entry) SetSingleton

func (e *Entry) SetSingleton(enabled bool)

SetSingleton 设置以单例模式运行的条目。 md5:6c81a3a09d0ef0b1

func (*Entry) SetStatus

func (e *Entry) SetStatus(status int) int

SetStatus 设置条目的状态。 md5:ea0ecb4171f3f017

func (*Entry) SetTimes

func (e *Entry) SetTimes(times int)

SetTimes 设置条目可以运行的时间。 md5:663af054d5aab5e9

func (*Entry) Start

func (e *Entry) Start()

Start 开始运行入口函数。 md5:aa729d73eb626ca1

func (*Entry) Status

func (e *Entry) Status() int

Status 返回条目的状态。 md5:6a9d3438dc575881

func (*Entry) Stop

func (e *Entry) Stop()

Stop 停止运行条目。 md5:06d53148d6536ce9

type JobFunc

type JobFunc = gtimer.JobFunc

JobFunc 是在cron中定时被调用的作业函数。 md5:476072dbc1ca96ff

Jump to

Keyboard shortcuts

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