
robfig/cron
A Go library for running functions on a cron-style schedule inside your own program.robfig/cron
- Stars
- 14.2k
- Forks
- 1.7k
- Licence
- MIT
- Language
- Go
- Last update
- 2.3 years ago
- Type
- Library
No commits in over a year — check for forks or alternatives before adopting.
What it is
robfig/cron is a Go library that lets a Go program run its own functions on a recurring schedule, using the cron timing format familiar from Linux. You import it into your code and register jobs with a schedule string, instead of setting up separate system cron entries. The README describes v3 as the current version, with support for Go Modules, optional seconds fields, timezone handling, and interceptors for behavior like panic recovery and skipping overlapping runs.
- Run a cleanup function every night at midnight inside a Go service
- Poll an external API every few minutes from a long-running Go process
- Schedule a report generation job in a specific timezone using CRON_TZ
Great for
- Go developers who need periodic tasks inside an application
- Teams that want job schedules managed in code rather than system crontab
- Projects that need the standard five-field cron format or the optional seconds field
Not ideal for
- Non-Go projects, since this is a Go library and the README gives no other language bindings
- Distributed scheduling across many servers, because the README does not describe clustering or persistence
- People who only need a one-off system job, where the OS crontab is simpler
How to get it
- 1
Install with a package manager
You'll need: Go 1.11 or later
Download the v3 release
go get github.com/robfig/cron/v3@v3.0.0 - 2
Run it
- Install the module with go get as shown in the README.
- Import github.com/robfig/cron/v3 in your Go program.
- Create a scheduler with cron.New() and register a job with AddFunc or a similar call.
- Call Start() to begin running scheduled jobs.
- 3
Get the most out of it
- Use cron.WithSeconds() if you need a seconds field in the schedule.
- Add cron.Recover(logger) through cron.WithChain if you want panics in jobs caught.
- Use CRON_TZ= in a schedule string to set the timezone for one job.
- Provide a logger through cron.WithLogger, using cron.VerbosePrintfLogger for Info logs.
Downloads
Strengths
- Uses the standard cron format by default, avoiding the non-standard seconds field of v1
- Interceptors (Chain and JobWrapper) can add panic recovery, overlap skipping or delaying, and logging
- Supports the logr logging interface for structured logs
Trade-offs
- Panics in jobs are not recovered by default in v3, so developers must opt in
- The README describes v1 and v2 as incompatible, so older code needs changes to upgrade
- The README is truncated and does not show full API details; the GoDoc link is the main reference
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.