Golang : Schedule Cron Jobs with Crontab

This golang tutorial help to create schedule a jon to execute at specific time interval

By the way, I started to engage in golang recently... I remember that I used Golang to do something in LeTV, and I had to give up golang because of various problems.

There is a function that requires regular execution tasks, because it is coupled with the internals of the project, so it is not suitable for operation with linux crontab. Find a popular golang cron module in github that is easy to use! We only need to register a bunch of tasks to the scheduler. 

Golang crontab project address:

Specific documentation:

The following is an example usage of robfig/cron. 

package main
import (
func main() {
i := 0
c := cron.New()
spec := "0 */1 * * * *"
c.AddFunc(spec, func() {
log.Println("start", i)

The following is the effect of the implementation of robfig/cron, the result is called once every minute as we set.
go run cron.go

2016/03/03 13:48:00 start 1
2016/03/03 13:49:00 start 2
2016/03/03 13:50:00 start 3
2016/03/03 13:51:00 start 4
2016/03/03 13:52:00 start 5
2016/03/03 13:53:00 start 6
2016/03/03 13:54:00 start 7

Never miss a post from Chris Gregori, when you sign up for Ednsquare.