cron
A dependency-free Go library for running recurring jobs on standard cron schedules, with functional options and composable job middleware.
Repository Health
Technical Analysis
robfig/cron is the de facto cron job scheduler for Go, letting programs register functions or Job implementations against standard cron expressions (* * * * *) or shorthand descriptors like @hourly and @every 1h30m. The scheduler runs entirely on the Go standard library — no external dependencies — coordinating a single background goroutine with channel-based synchronization so entries can be added, removed, or snapshotted safely from other goroutines while the cron loop is running.
Version 3 (the current major version, imported as github.com/robfig/cron/v3) rebuilt the library’s construction API around functional options (cron.New(cron.WithSeconds(), cron.WithChain(...))) and introduced a Chain/JobWrapper decorator system that lets callers compose cross-cutting behaviors — panic recovery, skip-if-still-running, delay-if-still-running, and structured logging — around any job without subclassing.
What You Get
- A
Cronscheduler type supportingAddFunc/AddJob,Remove,Entries,Start/Run, and a context-returningStopfor graceful shutdown - Standard 5-field cron parsing by default, with an opt-in 6-field seconds format for Quartz-style schedules via
WithSeconds() - Shorthand schedule descriptors (
@yearly,@monthly,@weekly,@daily,@hourly,@every <duration>) - A
Chain/JobWrappermiddleware system with built-inRecover,DelayIfStillRunning, andSkipIfStillRunningwrappers - Per-schedule timezone support via
CRON_TZ=prefix or a customLocation, correctly handling DST transitions - A pluggable
Loggerinterface compatible with the go-logr ecosystem, withPrintfLogger/VerbosePrintfLoggeradapters for the standardlogpackage
Common Use Cases
- Running periodic maintenance tasks (cache eviction, cleanup jobs, report generation) inside a long-running Go service
- Scheduling recurring background jobs in a self-hosted application without pulling in an external job queue or message broker
- Building internal tooling that needs cron-like scheduling embedded directly in a single Go binary
- Coordinating multiple periodic tasks with different timezones within one process using per-entry
CRON_TZoverrides - Wrapping scheduled jobs with panic recovery and overlap protection in production services via the Chain API
Under The Hood
Architecture
The Cron type (cron.go) coordinates its entry list through unbuffered channels — add, remove, snapshot, and stop — so the single background goroutine running run() never races with callers invoking AddFunc, Remove, or Entries from other goroutines. Each Entry pairs a Schedule (the SpecSchedule bitmask type in spec.go, or a ConstantDelaySchedule for @every) with a WrappedJob, produced by passing the user’s Job through the configured Chain (chain.go) at registration time. The run() loop sorts entries by next-fire time and sleeps on a single time.Timer sized to the soonest entry, re-evaluating on each wake, add, or remove. A ScheduleParser interface (parser.go) decouples spec-string parsing from the scheduler itself, so WithParser/WithSeconds can swap in alternate grammars without touching Cron. Changing the bitmask representation in SpecSchedule would require lockstep changes to both the six-field parser and every Next() calculation.
Tech Stack
The module (github.com/robfig/cron/v3, go.mod targets Go 1.12) has zero third-party runtime dependencies — it uses only the standard library (context, sort, sync, time, fmt, runtime, log, os, strings). There is no build tooling beyond go build/go test; a .travis.yml runs the test suite in CI. The Logger interface is deliberately shaped to be compatible with github.com/go-logr/logr without requiring it as a dependency.
Code Quality
Test coverage is extensive relative to the implementation — roughly 1,700 lines of tests (cron_test.go, parser_test.go, spec_test.go, chain_test.go, constantdelay_test.go, option_test.go) against under 1,500 lines of source. parser_test.go and spec_test.go use table-driven tests covering every field type, special character (* / , - ?), and explicit DST-transition fixtures; cron_test.go exercises concurrent add/remove/stop behavior. Exported types carry godoc comments, Parse functions return typed errors rather than panicking, and naming is consistent and idiomatic Go. No dedicated example test files or CONTRIBUTING guide were found, and there is no linter configuration beyond go vet/go test in CI.
API Design
The v3 rewrite replaced ad-hoc field setters with functional options (cron.New(cron.WithSeconds(), cron.WithChain(cron.Recover(logger)))), keeping the zero-value-friendly cron.New() as the common case. The Job/FuncJob pair lets callers register either a plain func() or a type implementing Run(), and the Chain/JobWrapper decorator pattern gives users a composable way to layer panic recovery, overlap protection, and logging onto jobs without wrapper boilerplate — an ergonomic touch that’s uncommon in scheduling libraries of this size. The underlying cron semantics follow the well-known standard format rather than introducing anything novel.
Used by 29 apps in this directory
Dokku
Devops · Hosting Control Panel
The smallest PaaS implementation you've ever seen — deploy apps via git push using Docker and Heroku buildpacks on your own server.
Fider
Customer Support · Product Management
Open-source feedback portal where customers submit, vote on, and track feature requests so product teams build what actually matters.
Gitea
Developer Tools · Devops · Project Management
Self-hosted DevOps in a single Go binary — Git hosting, GitHub Actions-compatible CI/CD, and 30+ package registries without any SaaS dependency.
Gotify
Developer Tools · Monitoring
A lightweight, self-hosted push notification server that sends and receives messages in real time over WebSocket, with a sleek web UI and a native Go plugin system.
Grafana
Analytics · Monitoring
The open-source observability platform that unifies metrics, logs, and traces from any data source into dynamic, queryable dashboards.
Hatchet
AI Development · Automation · Developer Tools
A Postgres-backed orchestration engine for background tasks, AI agents, and durable workflows that replaces Redis queues and multi-datastore durable execution platforms with a single self-hostable service.
Formance Ledger
Databases · Developer Tools · Invoicing Finance
The programmable open source core ledger for fintech — build money-moving applications with atomic multi-posting transactions, account-based modeling, and Numscript, a built-in DSL for financial logic.
Magic
AI Agents · Automation · Low Code Platforms
Magic is an enterprise-grade open-source AI agent platform combining a generalist AI agent, workflow engine, IM, and collaborative office system for running an AI-powered digital workforce.
Multica
AI Assistants · AI Development
Turn coding agents into real teammates — assign issues, track progress, and compound reusable skills across a vendor-neutral, self-hosted platform.