gocrontab

package module
Version: v0.0.0-...-aa69965 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2019 License: MIT Imports: 4 Imported by: 0

README

功能

  • 创建任务

  • 删除任务

  • 设定任务运行时间,间隔

  • 友好的设定时间方法,包括:间隔,秒,分,时,日

  • 支持带参数函数任务

Changelog

  • 2019.6.22 整理代码
  • 2018.4.24 新增支持带参数函数任务

使用

scheduler := gocrontab.NewSchedule()
scheduler.NewJob("test1").Every(10).Seconds().Do(func() {
	fmt.Println("test1......")
})

scheduler.Start()

scheduler.NewJob("test2").Every(15).Seconds().Do(func() {
	fmt.Println("test2.....")
})

fmt.Println(scheduler.Entries())
for {
	time.Sleep(15 * time.Second)

	scheduler.Stop()

	break
}

fmt.Println("删除", scheduler.RemoveJob("test2"))
fmt.Println("删除", scheduler.RemoveJob("test2"))

scheduler.NewJob("testc").Every(15).Minutes().Do(func() {
	fmt.Println("test2.....")
})

entries := scheduler.Entries()
for idx := range entries {
	fmt.Println(entries[idx].GetName())
}
fmt.Println(scheduler.Entries())

License

The MIT License (MIT) - see LICENSE for more details

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

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

func (*Job) At

func (j *Job) At(hour, min uint) *Job

At unit 时间:小时分钟,18, 20

func (*Job) Days

func (j *Job) Days() *Job

Days unit

func (*Job) Do

func (j *Job) Do(jobFunc interface{}, params ...interface{})

Do ...

func (*Job) Every

func (j *Job) Every(interval uint64) *Job

Every

func (*Job) GetName

func (j *Job) GetName() string

GetName ...

func (*Job) Hours

func (j *Job) Hours() *Job

Hours unit

func (*Job) Minutes

func (j *Job) Minutes() *Job

Minutes unit

func (*Job) Rename

func (j *Job) Rename(name string)

Rename ...

func (Job) Run

func (j Job) Run()

Run 运行 Job 使用 reflect 进行调用

func (*Job) Seconds

func (j *Job) Seconds() *Job

Seconds unit

type Scheduler

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

func NewSchedule

func NewSchedule() *Scheduler

NewSchedule 新建

func (*Scheduler) Entries

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

Entries ...

func (*Scheduler) Len

func (s *Scheduler) Len() int

Len ...

func (*Scheduler) Less

func (s *Scheduler) Less(i, j int) bool

Less 判断 i 是否在 j 之前

func (*Scheduler) NewJob

func (s *Scheduler) NewJob(Name string) *Job

NewJob

func (*Scheduler) RemoveJob

func (s *Scheduler) RemoveJob(name string) bool

RemoveJob ...

func (*Scheduler) Start

func (s *Scheduler) Start()

Start ...

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop ...

func (*Scheduler) Swap

func (s *Scheduler) Swap(i, j int)

Swap ...

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL