cronlib 可修改任务 推荐
最后更新于:2022-04-02 02:40:05
[TOC]
> [github](https://github.com/rfyiamcool/cronlib)
## 概述
Field name | Mandatory? | Allowed values | Allowed special characters
---------- | ---------- | -------------- | --------------------------
Seconds | Yes | 0-59 | * / , -
Minutes | Yes | 0-59 | * / , -
Hours | Yes | 0-23 | * / , -
Day of month | Yes | 1-31 | * / , - ?
Month | Yes | 1-12 or JAN-DEC | * / , -
Day of week | Yes | 0-6 or SUN-SAT | * / , - ?
## 安装
`go get github.com/rfyiamcool/cronlib`
## 实例
注意不要在 init中初始化 `cron = cronlib.New()
`
## 循环实例(注意避免注意指针影响)
## 更新/停止操作
';
main.go
``` package main import ( "fmt" "github.com/rfyiamcool/cronlib" ) var ( cron *cronlib.CronSchduler ) func main() { cron = cronlib.New() a := []struct { cron string name string url string }{ { name: "hello", cron: "*/1 * * * * *", url: "hello", }, { name: "word", cron: "*/2 * * * * *", url: "word", }, } for _, s := range a { b :=s model, e := cronlib.NewJobModel( b.cron, func() { fmt.Println(b.url) }) if e != nil { panic(e) } err := cron.Register(b.name, model) if err != nil { panic(err) } } cron.Start() select {} } ```## 更新/停止操作