cron

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cron 实现计划任务模块:按 cron 表达式定时执行命令或 HTTP 请求,并保留最近的执行记录。

Index

Constants

View Source
const (
	TypeCommand = "command"
	TypeHTTP    = "http"
)

任务类型

View Source
const ID = "cron"

ID 是模块标识。

Variables

This section is empty.

Functions

This section is empty.

Types

type Module

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

Module 是计划任务模块。

func New

func New() *Module

New 创建模块。

func (*Module) ID

func (m *Module) ID() string

ID 实现 module.Module。

func (*Module) Init

func (m *Module) Init(env module.Env) error

Init 实现 module.Module。

func (*Module) Routes

func (m *Module) Routes(r module.Router)

Routes 实现 module.Module。

func (*Module) Start

func (m *Module) Start(ctx context.Context) error

Start 实现 module.Module。

func (*Module) Stop

func (m *Module) Stop() error

Stop 实现 module.Module,等待正在执行的任务结束。

func (*Module) Title

func (m *Module) Title() string

Title 实现 module.Module。

type Run

type Run struct {
	Start    time.Time `json:"start"`
	Duration int64     `json:"durationMs"`
	OK       bool      `json:"ok"`
	Output   string    `json:"output"`
	Manual   bool      `json:"manual"`
	// Attempts 为本次执行实际尝试的次数(含重试),无重试时为 1
	Attempts int `json:"attempts"`
}

Run 是一次执行记录。

type Task

type Task struct {
	Key  string `json:"key"`
	Name string `json:"name"`
	// Group 为列表中的分组名称,只影响管理界面的展示,留空为未分组
	Group  string `json:"group"`
	Enable bool   `json:"enable"`
	// Spec 为 cron 表达式,例如 "0 3 * * *"、"*/30 * * * * *"、"@every 10m"
	Spec    string         `json:"spec"`
	Type    string         `json:"type"`
	Command string         `json:"command"`
	HTTP    webhook.Config `json:"http"`
	Remark  string         `json:"remark"`
	// Retries 为失败后的自动重试次数(0 不重试),RetryInterval 为两次尝试之间的间隔秒数
	Retries       int `json:"retries"`
	RetryInterval int `json:"retryInterval"`
	// MuteFail 为 true 时该任务最终失败也不发布 cron.failed 事件;默认 false,已有任务保持通知
	MuteFail bool `json:"muteFail"`
}

Task 是一个计划任务。

func (*Task) Validate

func (t *Task) Validate() error

Validate 校验任务。

type TaskView

type TaskView struct {
	Task
	Running bool      `json:"running"`
	NextRun time.Time `json:"nextRun,omitzero"`
	History []Run     `json:"history"`
}

TaskView 是带运行状态的任务。

Jump to

Keyboard shortcuts

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