dcron

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Example (CronAddSingleton)
package main

import (
	"github.com/osgochina/donkeygo/os/dcron"
	"github.com/osgochina/donkeygo/os/dlog"
	"time"
)

func main() {
	dcron.AddSingleton("* * * * * *", func() {
		dlog.Println("doing")
		time.Sleep(2 * time.Second)
	})
	select {}
}
Output:

Index

Examples

Constants

View Source
const (
	StatusReady   = dtimer.StatusReady   //已就绪
	StatusRunning = dtimer.StatusRunning // 运行中
	StatusStopped = dtimer.StatusStopped //已停止
	StatusClosed  = dtimer.StatusClosed  // 已关闭

)

Variables

This section is empty.

Functions

func CronPlan added in v0.0.6

func CronPlan(pattern string, t time.Time, queryTimes ...int) ([]time.Time, error)

CronPlan 获取表达式的执行计划

func DelayAdd

func DelayAdd(delay time.Duration, pattern string, job func(), name ...string)

DelayAdd 添加一个指定延迟时间,再解析规则的定时任务到处理器

func DelayAddOnce

func DelayAddOnce(delay time.Duration, pattern string, job func(), name ...string)

DelayAddOnce 添加一个指定延迟时间,在解析规则,只运行一次的定时任务

func DelayAddSingleton

func DelayAddSingleton(delay time.Duration, pattern string, job func(), name ...string)

DelayAddSingleton 添加指定延迟时间,再解析规则,并且运行时候有并发限制的的任务

func DelayAddTimes

func DelayAddTimes(delay time.Duration, pattern string, times int, job func(), name ...string)

DelayAddTimes 添加一个指定延迟时间,再解析定时规则,并且运行指定运行次数的定时任务。

func GetLogLevel

func GetLogLevel() int

GetLogLevel 获取日志记录的级别

func GetLogPath

func GetLogPath() string

GetLogPath 获取日志路径

func Remove

func Remove(name string)

Remove 通过名字移除定时任务

func SetLogLevel

func SetLogLevel(level int)

SetLogLevel 设置日志记录的级别

func SetLogPath

func SetLogPath(path string)

SetLogPath 设置定时任务处理详情的日志记录文件路径

func Size

func Size() int

Size 获取处理器中一共有多少任务

func Start

func Start(name string)

Start 启动指定任务

func Stop

func Stop(name string)

Stop 关闭指定任务

Types

type Cron

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

func NewCron

func NewCron() *Cron

NewCron 创建Cron对象

func (*Cron) Add

func (that *Cron) Add(pattern string, job func(), name ...string) (*Entry, error)

Add 添加定时任务

func (*Cron) AddOnce

func (that *Cron) AddOnce(pattern string, job func(), name ...string) (*Entry, error)

AddOnce 添加只执行一次的定时任务

func (*Cron) AddSingleton

func (that *Cron) AddSingleton(pattern string, job func(), name ...string) (*Entry, error)

AddSingleton 添加单例模式的定时任务

func (*Cron) AddTimes

func (that *Cron) AddTimes(pattern string, times int, job func(), name ...string) (*Entry, error)

AddTimes 添加指定执行次数的定时任务

func (*Cron) Close

func (that *Cron) Close()

Close 关闭定时任务器

func (*Cron) DelayAdd

func (that *Cron) DelayAdd(delay time.Duration, pattern string, job func(), name ...string)

DelayAdd 延迟添加定时任务

func (*Cron) DelayAddOnce

func (that *Cron) DelayAddOnce(delay time.Duration, pattern string, job func(), name ...string)

DelayAddOnce 延迟添加执行一次的定时任务

func (*Cron) DelayAddSingleton

func (that *Cron) DelayAddSingleton(delay time.Duration, pattern string, job func(), name ...string)

DelayAddSingleton 延迟添加单例模式的定时任务

func (*Cron) DelayAddTimes

func (that *Cron) DelayAddTimes(delay time.Duration, pattern string, times int, job func(), name ...string)

DelayAddTimes 延迟添加指定执行次数的定时任务

func (*Cron) Entries

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

Entries 导出任务切片列表

func (*Cron) GetLogLevel

func (that *Cron) GetLogLevel() int

GetLogLevel 获取日志等级

func (*Cron) GetLogPath

func (that *Cron) GetLogPath() string

GetLogPath 获取日志路径

func (*Cron) Remove

func (that *Cron) Remove(name string)

Remove 移除定时任务

func (*Cron) Search

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

Search 通过任务名查找任务

func (*Cron) SetLogLevel

func (that *Cron) SetLogLevel(level int)

SetLogLevel 设置日志等级

func (*Cron) SetLogPath

func (that *Cron) SetLogPath(path string)

SetLogPath 设置日志路径

func (*Cron) Size

func (that *Cron) Size() int

Size 有多少个定时任务在处理器中

func (*Cron) Start

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

Start 启动定时器

func (*Cron) Stop

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

Stop 关闭定时任务

type Entry

type Entry struct {
	Name string    // 任务的自定义名字
	Job  func()    //任务处理方法地址
	Time time.Time // 任务建立时间
	// contains filtered or unexported fields
}

Entry 定时任务条目

func Add

func Add(pattern string, job func(), name ...string) (*Entry, error)

Add 添加一个定时任务到处理器

func AddOnce

func AddOnce(pattern string, job func(), name ...string) (*Entry, error)

AddOnce 添加一个只执行一次的定时任务到处理器

func AddSingleton

func AddSingleton(pattern string, job func(), name ...string) (*Entry, error)

AddSingleton 添加一个并发限制的定时任务到处理器

func AddTimes

func AddTimes(pattern string, times int, job func(), name ...string) (*Entry, error)

AddTimes 添加一个限制执行次数的定时任务到处理器

func Entries

func Entries() []*Entry

Entries 返回处理器中的任务列表

func Search(name string) *Entry

Search 通过名字搜索处理器中的任务

func (*Entry) Close

func (that *Entry) Close()

Close 关闭当前服务

func (*Entry) IsSingleton

func (that *Entry) IsSingleton() bool

IsSingleton 判断任务是否是单例模式

func (*Entry) Next added in v0.0.6

func (that *Entry) Next(t time.Time, queryTimes ...int) ([]time.Time, error)

Next 获取下一次运行的时间 t: 指定的时间 queryTimes: 要获取接下来几次

func (*Entry) SetSingleton

func (that *Entry) SetSingleton(enabled bool)

SetSingleton 设置任务单例模式开关

func (*Entry) SetStatus

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

SetStatus 设置任务状态

func (*Entry) SetTimes

func (that *Entry) SetTimes(times int)

SetTimes 设置任务运行次数

func (*Entry) Start

func (that *Entry) Start()

Start 开始运行任务

func (*Entry) Status

func (that *Entry) Status() int

Status 获取任务状态

func (*Entry) Stop

func (that *Entry) Stop()

Stop 停止任务

Jump to

Keyboard shortcuts

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