Skip to content

csunny/go-cron

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-cron

a crontab librarys by golang and precision to second and functional enhancement is simple and easy to use.

demo code

package main

import (
	"fmt"
	"../cron"
)

type DemoLogger struct{}

func (self *DemoLogger) Logger(format string, args ...interface{}) {
	//handle log
}

func ExecDemo() {
	fmt.Println("hello world")
}

//precision to second
var c = cron.New()

func main() {
	log := &DemoLogger{}
	//add job with log
	c.AddJob("*/1 * * * * *", ExecDemo, log)
	//add job with no log
	jobid, err := c.AddJob("*/1 * * * * *", ExecDemo, nil)
	c.Start(jobid)
	c.Stop(jobid)
	c.Delete(jobid)
	//store this jobid maybe you need use it

	//When your program restarted and you maybe need rebuild you jobs
	//from config file or db you can use like this
        for _,job:=range GetJobs() {
	      execFunc:=makeFunc(job)
	      //c.AddJobWithJobID("*/1 * * * * *",ExecDemo,my_jobid,log)
	      id, _ := c.AddJobWithJobID(job.spec, execFunc, job.jobid, log)
	      c.Start(id)
  	}
}

About

A Distrubuted Second Level Timed task use golang.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%