# cron **Repository Path**: wqt/cron ## Basic Information - **Project Name**: cron - **Description**: 说明: https://godoc.org/github.com/qingtao/cron - **Primary Language**: Go - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-05-24 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # cron ## 提供一个基本的定时任务管理工具. ### GoDoc:[![GoDoc](https://godoc.org/github.com/qingtao/cron?status.svg)](https://godoc.org/github.com/qingtao/cron) ### 使用方法: ```go package main import ( "context" "fmt" "time" "github.com/qingtao/cron" ) func main() { //新的context和cancel ctx, cancel := context.WithCancel(context.Background()) //创建新的cron.Cron c := cron.New(cancel) //处理错误 go cr.Wait(func(err error) { fmt.Println(err) }) //启动计划任务管理进程 go c.Start(ctx) //定义时间 s1 := "1/2 * * * * *" s2 := "15 13 * * * *" //添加计划任务 c.AddFunc(ctx, "s1", s1, 900, func() { fmt.Printf("s1 %s: %s\n", s1, time.Now()) }) c.AddFunc(ctx, "s2", s2, 900, func() { fmt.Printf("s2 %s: %s\n", s2, time.Now()) }) } ```