在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:go-co-op/gocron开源软件地址:https://github.com/go-co-op/gocron开源编程语言:Go 99.9%开源软件介绍:gocron: A Golang Job Scheduling Package.gocron is a job scheduling package which lets you run Go functions at pre-determined intervals using a simple, human-friendly syntax. gocron is a Golang scheduler implementation similar to the Ruby module clockwork and the Python job scheduling package schedule. See also these two great articles that were used for design input: If you want to chat, you can find us at Slack! Concepts
Exampless := gocron.NewScheduler(time.UTC)
s.Every(5).Seconds().Do(func(){ ... })
// strings parse to duration
s.Every("5m").Do(func(){ ... })
s.Every(5).Days().Do(func(){ ... })
s.Every(1).Month(1, 2, 3).Do(func(){ ... })
// set time
s.Every(1).Day().At("10:30").Do(func(){ ... })
// set multiple times
s.Every(1).Day().At("10:30;08:00").Do(func(){ ... })
s.Every(1).Day().At("10:30").At("08:00").Do(func(){ ... })
// Schedule each last day of the month
s.Every(1).MonthLastDay().Do(func(){ ... })
// Or each last day of every other month
s.Every(2).MonthLastDay().Do(func(){ ... })
// cron expressions supported
s.Cron("*/1 * * * *").Do(task) // every minute
// you can start running the scheduler in two different ways:
// starts the scheduler asynchronously
s.StartAsync()
// starts the scheduler and blocks current execution path
s.StartBlocking() For more examples, take a look in our go docs Options
There are several options available to restrict how jobs run:
TagsJobs may have arbitrary tags added which can be useful when tracking many jobs. The scheduler supports both enforcing tags to be unique and when not unique, running all jobs with a given tag. s := gocron.NewScheduler(time.UTC)
s.TagsUnique()
_, _ = s.Every(1).Week().Tag("foo").Do(task)
_, err := s.Every(1).Week().Tag("foo").Do(task)
// error!!!
s := gocron.NewScheduler(time.UTC)
s.Every(2).Day().Tag("tag").At("10:00").Do(task)
s.Every(1).Minute().Tag("tag").Do(task)
s.RunByTag("tag")
// both jobs will run FAQ
Looking to contribute? Try to follow these guidelines:
DesignJetbrains supports this project with GoLand licenses. We appreciate their support for free and open source software! |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论