It's not who you are underneath, it's what you do that defines you

Brick walls are there for a reason :they let us prove how badly we want things

cron 简单任务调度 go

package main

import (
	"github.com/robfig/cron"
	"log"
)

func main() {
	i := 0
	c := cron.New()
	spec :="50 7 * * * ?"// "*/5 * * * * ?"
	c.AddFunc(spec, func() {
		i++
		log.Println("cron running:", i)

	})
	c.Start()
	select{}
}

 任意时间的xx:07:50执行任务

API server listening at: 127.0.0.1:58401
2018/01/09 14:07:50 cron running: 1

spec :="*/5 * * * * ?"

  每5秒执行一次任务

API server listening at: 127.0.0.1:58900
2018/01/09 14:11:30 cron running: 1
2018/01/09 14:11:35 cron running: 2
2018/01/09 14:11:40 cron running: 3
2018/01/09 14:11:45 cron running: 4
2018/01/09 14:11:50 cron running: 5
2018/01/09 14:11:55 cron running: 6
2018/01/09 14:12:00 cron running: 7
2018/01/09 14:12:05 cron running: 8
2018/01/09 14:12:10 cron running: 9

posted @ 2018-01-09 14:14  gbat  阅读(869)  评论(0编辑  收藏  举报

It's not who you are underneath, it's what you do that defines you

Brick walls are there for a reason :they let us prove how badly we want things