cron
a cron library for go
A Go library that lets your program run functions on a schedule using cron-style timing strings, like 'every hour' or 'midnight on Fridays', without relying on the operating system's cron tool.
This is a library for the Go programming language that lets a program run tasks on a schedule. The name comes from cron, a long-standing tool on Unix and Linux systems for running jobs automatically at set times, such as every minute, every hour, or at midnight on the first of the month. Instead of relying on the operating system's cron, this library brings that same scheduling ability directly inside a Go program, so a developer can say what should happen and when, all in their own code.
The README is written mainly for developers and focuses on version 3 of the library, which was a major update. It shows how to download and import the package, and notes that it needs Go version 1.11 or later. Most of the document explains what changed in version 3 and what existing users need to adjust when upgrading from older versions, so it reads as release notes rather than a beginner tutorial.
Schedules are described using a cron specification, which is a compact line of fields that say which minutes, hours, days, and months a job should run. The README explains that there are two common formats for this: the standard format used by the Linux cron utility, and a different format used by a Java tool called Quartz. Version 3 now uses the standard format by default, where the first field is the minute, and it offers an option to add a seconds field for finer control. Time zones can be set per schedule.
The library also added a feature called job wrappers, which let you attach extra behavior around your scheduled tasks. Examples given include recovering from crashes inside a job, skipping or delaying a job if its previous run has not finished yet, and logging each time a job runs.
The document lists several specific bug fixes and warns that version 3 is not fully compatible with versions 1 and 2, giving code snippets for adapting older programs.
Where it fits
- Schedule a Go function to run every hour to send a digest email or sync data.
- Run a cleanup job at midnight every day inside a long-running Go web server.
- Skip a scheduled task if its previous run hasn't finished yet, using built-in job wrappers.
- Log every scheduled job execution automatically with the provided logging wrapper.