📚 cronticker - Awesome Go Library for Job Scheduler

Go Gopher mascot for cronticker

A ticker implementation to support cron schedules.

🏷️ Job Scheduler
📂 Libraries for scheduling jobs.
16 stars
View on GitHub 🔗

Detailed Description of cronticker

cronticker

Golang ticker that works with Cron scheduling.

CircleCI Codecov Go Report Card

Import it

go get github.com/krayzpipes/cronticker/cronticker
import "github.com/krayzpipes/cronticker/cronticker"

Usage

Create a new ticker:

ticker, err := NewTicker("TZ=America/New_York 0 0 0 ? * SUN")

Check the ticker's channel for the next tick:

tickerTime := <-ticker.C

Reset the ticker to a new cron schedule

err := ticker.Reset("0 0 0 ? * MON,TUE,WED")

Stop the ticker

ticker.Stop()

Use defer ticker.Stop() whenever you can to ensure the cleanup of goroutines.

ticker, _ := NewTicker("@daily")
defer ticker.Stop()

Cron Schedule Format

The Cron schedule can be in Unix or Quartz format. Directives like '@weekly' or '@daily' can also be parsed as defined in the package github.com/robfig/cron/v3.

You may add the TimeZone/location to the beginning of the cron schedule to change the time zone. Default is UTC if TZ=Whatever is not prepended to the cron schedule.

Examples

Cron ScheduleType/FormatDescription
"TZ=America/Los_Angeles 0 0 * * *"UnixDaily at 12 AM in Los Angeles
"TZ=America/Los_Angeles 0 0 0 ? * MON"QuartzMondays at 12 AM in Los Angeles
"TZ=America/Los_Angeles @daily"DirectiveDaily at 12 AM in Los Angeles
"@daily"DirectiveDaily at 12 AM UTC

You may also use the following characters:

CharacterDescriptionExample
-Range4-5
/Step0/5
*Any*/5
,List1,4,5