cron

package
v0.0.0-...-7113a4a Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

定时调度器,必须先调用Init()初始化

┌───────────── minute (0 - 59) │ ┌───────────── hour (0 - 23) │ │ ┌───────────── day of the month (1 - 31) │ │ │ ┌───────────── month (1 - 12) │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday; │ │ │ │ │ 7 is also Sunday on some systems) │ │ │ │ │ │ │ │ │ │ * * * * * <command to execute>

用,指定多个时间,用*/指定间隔时间执行 */5 1,2,3 * * * echo hello world

Index

Constants

View Source
const (
	// cron表达式
	Minutely = "* * * * *" // 每分钟
	Hourly   = "@hourly"   // 每小时
	Weekly   = "@weekly"   // 每周
	Monthly  = "@monthly"  // 每月
)

Variables

This section is empty.

Functions

func AddFunc

func AddFunc(spec string, cmd func()) error

AddFunc adds a func to the Cron to be run on the given schedule. Cron will run them in their own goroutines. 不会立即运行

func AddFuncNow

func AddFuncNow(spec string, cmd func()) error

AddFuncNow adds a func to the Cron to be run on the given schedule. Cron will run them in their own goroutines. 会立即运行一次

func Daily

func Daily(hour int) string

Daily 每天几点 @daily 不准,可能一天执行两次 有时候在00:00:00执行 有时候在23:59:59执行

func Every

func Every(duration string) string

Every 指定间隔时间 1ms -1s 1h0.5m 参考time.ParseDuration函数

func Init

func Init()

Init 初始化调度器

func Stop

func Stop() context.Context

Stop stops the cron scheduler if it is running; otherwise it does nothing. does not stop any jobs already running A context is returned so the caller can wait for running jobs to complete.

Types

This section is empty.

Jump to

Keyboard shortcuts

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