cron

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cron

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

Cron 定时任务管理器

func NewCron

func NewCron() *Cron

NewCron 创建 Cron

func (*Cron) Remove

func (c *Cron) Remove(id string)

Remove 移除调度

func (*Cron) Run

func (c *Cron) Run()

Run 运行 Cron

func (*Cron) Schedule

func (c *Cron) Schedule(schedule Schedule, jobFunc func(), id string)

Schedule 添加调度

func (*Cron) Stop

func (c *Cron) Stop()

Stop 停止 Cron

type Job

type Job struct {
	ID         string
	Name       string
	Schedule   string
	Task       string
	TargetChat string
	Enabled    bool
	LastRun    time.Time
	NextRun    time.Time
	RunCount   int
}

Job 定时任务

type Schedule

type Schedule interface {
	Next(time.Time) time.Time
}

Schedule 调度接口

func Parse

func Parse(spec string) (Schedule, error)

Parse 解析 cron 表达式(简化版)

type ScheduleFunc

type ScheduleFunc func(time.Time) time.Time

ScheduleFunc 调度函数

func (ScheduleFunc) Next

func (f ScheduleFunc) Next(t time.Time) time.Time

Next 实现 Schedule 接口

type ScheduledJob

type ScheduledJob struct {
	ID       string
	Schedule Schedule
	Func     func()
	Next     time.Time
}

ScheduledJob 定时任务

type Scheduler

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

Scheduler 定时任务调度器

func NewScheduler

func NewScheduler(bus *bus.MessageBus, provider providers.Provider, sessionMgr *session.Manager) *Scheduler

NewScheduler 创建调度器

func (*Scheduler) AddJob

func (s *Scheduler) AddJob(job *Job) error

AddJob 添加任务

func (*Scheduler) DisableJob

func (s *Scheduler) DisableJob(id string) error

DisableJob 禁用任务

func (*Scheduler) EnableJob

func (s *Scheduler) EnableJob(id string) error

EnableJob 启用任务

func (*Scheduler) GetJob

func (s *Scheduler) GetJob(id string) (*Job, bool)

GetJob 获取任务

func (*Scheduler) ListJobs

func (s *Scheduler) ListJobs() []*Job

ListJobs 列出所有任务

func (*Scheduler) RemoveJob

func (s *Scheduler) RemoveJob(id string) error

RemoveJob 移除任务

func (*Scheduler) Start

func (s *Scheduler) Start(ctx context.Context) error

Start 启动调度器

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop 停止调度器

Jump to

Keyboard shortcuts

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