cronserver

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterCron

func RegisterCron(cronName string, cron Interface)

func Run

func Run(ctx context.Context, configPath string)

Types

type Base

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

func (*Base) AddBaseTaskList

func (b *Base) AddBaseTaskList(task func(context.Context))

func (*Base) AddProcessAddTaskList

func (b *Base) AddProcessAddTaskList(task func(context.Context))

func (*Base) Before

func (b *Base) Before(name string, maxConcurrencyCnt int)

func (*Base) Defer

func (b *Base) Defer(ctx context.Context)

func (*Base) GetIsRun

func (b *Base) GetIsRun(context.Context) bool

func (*Base) Init

func (b *Base) Init(_ Interface)

func (*Base) Process

func (b *Base) Process(context.Context)

func (*Base) Run

func (b *Base) Run(ctx context.Context)

type Config

type Config struct {
	IsRunCron bool
	CronList  []ConfigItem
}

type ConfigItem

type ConfigItem struct {
	Name              string
	MaxConcurrencyCnt int

	JobType                 string
	CronJobParams           CronJobParams
	DurationJobParams       DurationJobParams
	DurationRandomJobParams DurationRandomJobParams
}

type CronJobParams

type CronJobParams struct {
	Crontab string
}

type DurationJobParams

type DurationJobParams struct {
	EveryMillisecond int64
}

type DurationRandomJobParams

type DurationRandomJobParams struct {
	MinMillisecond int64
	MaxMillisecond int64
}

type Interface

type Interface interface {
	GetIsRun(context.Context) bool
	AddBaseTaskList(task func(context.Context))
	AddProcessAddTaskList(task func(context.Context))

	// Init 初始化只会执行一次
	Init(base Interface)
	Process(context.Context)

	Before(name string, maxConcurrencyCnt int)
	Run(context.Context)
	Defer(context.Context)
}

Interface 执行顺序 Before->Process->Run->Defer 只建议重写 Init 和 Process Init 添加固定执行的脚本,使用 AddBaseTaskList 添加,尽量通过该方法添加 Process 添加运行中才能确定执行的脚本,使用 AddProcessAddTaskList 添加

Jump to

Keyboard shortcuts

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