Exemple #1
0
func main() {

	var minutes = flag.Uint64("minites", 60, "how often would you like to check for new tv shows (in minutes)")
	flag.Parse()

	file, err := os.OpenFile("./testlogfile.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		fmt.Printf("Error opening logging file: %v", err)
	}
	defer file.Close()
	log.SetOutput(file)

	s := gocron.NewScheduler()
	s.Every(*minutes).Seconds().Do(task)
	<-s.Start()

}
func main() {
	// Do jobs with params
	gocron.Every(1).Second().Do(taskWithParams, 1, "hello")

	// Do jobs without params
	gocron.Every(1).Second().Do(task)
	gocron.Every(2).Seconds().Do(task)
	gocron.Every(1).Minute().Do(task)
	gocron.Every(2).Minutes().Do(task)
	gocron.Every(1).Hour().Do(task)
	gocron.Every(2).Hours().Do(task)
	gocron.Every(1).Day().Do(task)
	gocron.Every(2).Days().Do(task)

	// Do jobs on specific weekday
	gocron.Every(1).Monday().Do(task)
	gocron.Every(1).Thursday().Do(task)

	// function At() take a string like 'hour:min'
	gocron.Every(1).Day().At("10:30").Do(task)
	gocron.Every(1).Monday().At("18:30").Do(task)

	// remove, clear and next_run
	_, time := gocron.NextRun()
	fmt.Println(time)

	// gocron.Remove(task)
	// gocron.Clear()

	// function Start start all the pending jobs
	<-gocron.Start()

	// also , you can create a your new scheduler,
	// to run two scheduler concurrently
	s := gocron.NewScheduler()
	s.Every(3).Seconds().Do(task)
	<-s.Start()
}
Exemple #3
0
func main() {
	scheduler := gocron.NewScheduler()
	localLogger := log.New(os.Stdout, "[martini] ", 0)
	cfapp, _ := cfenv.Current()
	m := martini.Classic()
	m.Use(render.Renderer())
	m.Use(martini.Static("public"))
	m.Get("/", func(params martini.Params, log *log.Logger, r render.Render) {
		r.HTML(SuccessStatus, "index", nil)
	})

	m.Get("/v1/info/apps", func(log *log.Logger, r render.Render) {
		r.JSON(200, localCache.AppsBlob)
	})

	m.Get("/v1/info/users", func(log *log.Logger, r render.Render) {
		r.JSON(200, localCache.UserBlob)
	})

	m.Get("/v1/info/events", func(log *log.Logger, r render.Render) {
		r.JSON(200, localCache.EventsBlob)
	})

	scheduler.Every(10).Seconds().Do(func() {
		FetchEventsInfo(cfapp, localLogger)
	})
	scheduler.Every(1).Minute().Do(func() {
		FetchUserInfo(cfapp, localLogger)
	})
	scheduler.Every(1).Minute().Do(func() {
		FetchAppsInfo(cfapp, localLogger)
	})
	scheduler.RunAll()
	go func() {
		scheduler.Start()
	}()
	m.Run()
}