ConcurrencyCron  - go多协程定时任务调度

lsint 2019-12-25 13:18:03
ConcurrentCron is a task scheduler that supports high concurrency at the same time which lets you run Go functions periodically at pre-determined interval using a simple, human-friendly syntax. You can run this scheduler in the following way func test(num int) { fmt.Println("before:im a task", num) time.Sleep(10 * time.Second) fmt.Println("after:im a task", num, time.Now()) } func main() { scheduler, err := ConcurrencyCron.NewScheduler(200) //200 is the number of tasks that can be run in parallel if err != nil { fmt.Println(err) } for i := 0; i < 200; i++ { scheduler.Every(1).Seconds().Do(test, i) scheduler.Every(1).Minutes().Do(test, 1000+i) scheduler.Every(1).Hours().Do(test, 10000+i) } ctx, cancel := context.WithCancel(context.Background()) scheduler.Start(ctx) ch := make(chan bool) <-ch //test scheduler.Stop(cancel) //stop the tasks } This article refers to some of jasonlvhit/gocron's ideas and things, the specific timing tasks are the same as gocron, you can refer to his project Thank you for the support and understanding ,jasonlvhit!
    公告

    《从零开始开发BBS》课程上线啦,快来跟着我一步步搭建属于你的BBS吧。

    课程地址:https://www.shiyanlou.com/courses/1436
    9折优惠邀请码: ZHwfIjb1

    该课程会带领大家一步步的了解并熟悉Go语言开发,如果你是一个Go语言初学者,或者正准备学习Go语言,那么这个课程非常适合你。如果你熟练掌握了本课程中的知识点,相信你就已经入门Go语言开发,并能胜任日常的开发工作了。