Thanks to visit codestin.com
Credit goes to github.com

Skip to content

leprosus/golang-cron

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang jobs scheduler

Create new cron

import cron "github.com/leprosus/golang-cron"

c := cron.New(time.Minute)

Add job and schedule

c.RegisterJob("job", func () {
//Do something here
})

scheduleId := c.AddSchedule("job", func (tm time.Time) (ok bool) {
// It fires an execution of job "job" every even second

return tm.Second()%2 == 0
})

Remove schedule and job

c.DelSchedule("job", scheduleId)

c.UnregisterJob("job")

List all methods

  • New(ticker) - creates new cron
  • RegisterJob(name, func) - registers the new job with own name and function to execute when a schedule time will come
  • AddSchedule(name, handler) - adds schedule for a job with name and time handler and returns schedule ID
  • DelSchedule(scheduleId) - delete schedule by ID
  • UnregisterJob(name) - unregisters a job and all schedules that were connected with its

About

The package helps to schedule jobs tasks in any golang application

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages