xcron

package
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: BSD-3-Clause-Clear Imports: 5 Imported by: 0

Documentation

Overview

定时任务脚本

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hours

func Hours(h int, job CronTab)

添加x小时执行的任务

h	多少小时执行一次
job	待运行的任务结构配置

func HoursNext

func HoursNext(h int, job CronTab)

添加x小时执行的任务[不重启]

h	多少小时执行一次
job	待运行的任务配置结构

func Minutes

func Minutes(min int, job CronTab)

添加每X分钟执行的任务

min	多少分钟执行一次
job	待运行的任务配置结构

func MinutesNext

func MinutesNext(min int, job CronTab)

添加每X分钟执行的任务[不重启]

min	多少分钟执行一次
job	待运行的任务配置结构

func Restart

func Restart()

重启定时任务【会移除所有的定时任务ID,然后重新插入】

此处采用停止清空的形式来重启

func Spec

func Spec(spec string, job CronTab)

按照指定的spec进行执行任务

spec	指定运行的规则:分 时 日 月份 周几(具体规则参考Linux系统的crontab)
job		要运行的任务的Tab结构配置

func SpecNext

func SpecNext(spec string, job CronTab)

按照指定的spec进行执行任务[不重启]

spec	指定运行的规则:分 时 日 月份 周几(具体规则参考Linux系统的crontab)
job		要运行的任务的Tab结构

func SwitchPause

func SwitchPause(key string, pause bool)

切换任务key的暂停/启用状态

key		Crontab任务的下标关键词key
pause	暂停状态 true-暂停此任务 false-继续运行此任务

func Time

func Time(h, m int, job CronTab)

添加x小时执行的任务

h,m	几时几分
job	待运行的任务配置结构

func TimeNext

func TimeNext(h, m int, job CronTab)

添加x小时执行的任务[不重启]

h,m	几时几分
job	待运行的任务配置结构

Types

type Config

type Config struct {
	Tables []CronTab // 定时任务列表
	Keys   []string  // 已注册的key下标
	sync.Mutex
	// contains filtered or unexported fields
}

配置项结构体

type CronTab

type CronTab struct {
	Spec      string       `json:"spec"`       // 定时任务的运行规则
	Key       string       `json:"key"`        // 定时任务的运行下标
	Name      string       `json:"name"`       // 定时任务的运行名称
	Desc      string       `json:"desc"`       // 定时任务的运行描述
	Func      func()       `json:"-"`          // 运行函数
	ExecId    cron.EntryID `json:"exec_id"`    // 运行ID
	Error     string       `json:"error"`      // 运行错误原因
	IsPause   bool         `json:"is_pause"`   // 是否暂停
	StartTime string       `json:"start_time"` // 开始分派时间
}

定时任务的配置字段标识

type Statusstruct

type Statusstruct struct {
	Status   bool      `json:"status"`    // 运行状态
	Count    int       `json:"count"`     // 总注册条数
	RunCount int       `json:"run_count"` // 运行条数
	Tables   []CronTab `json:"tables"`    // 当前配置的任务规则表
}

状态结构数据返回

func Status

func Status() *Statusstruct

获取xcron的运行状态

Jump to

Keyboard shortcuts

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