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

whutwxn • 7875 次点击    
这是一个分享于 的项目,其中的信息可能已经有所发展或是发生改变。
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!
授权协议:
BSD
开发语言:
golang 查看源码»
7875 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传