cron

A dependency-free Go library for running recurring jobs on standard cron schedules, with functional options and composable job middleware.

Library
Go
vv3.0.1
14,193 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
45 /100 Fair
Development Activity 0
Maintenance 0
Community 80
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
71 /100 Good
Architecture 80
Code Quality 85
Innovation 65
Learning Curve 55

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 Cron scheduler type supporting AddFunc/AddJob, Remove, Entries, Start/Run, and a context-returning Stop for 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/JobWrapper middleware system with built-in Recover, DelayIfStillRunning, and SkipIfStillRunning wrappers
  • Per-schedule timezone support via CRON_TZ= prefix or a custom Location, correctly handling DST transitions
  • A pluggable Logger interface compatible with the go-logr ecosystem, with PrintfLogger/VerbosePrintfLogger adapters for the standard log package

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_TZ overrides
  • 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

Go
81%
GPL 3.0

Navidrome

File Storage · Music Audio

24,331

Run your own personal Spotify — stream your entire music collection from any device, anywhere, forever.

View details
91
Repo Health
81
Technical
66
Dependency
Built with
Go 81%
JavaScript 15%
Updated 1 weeks ago
Go
98%
Apache 2.0

Nightingale

Monitoring

13,383

Open-source alerting engine that connects to any time-series or log data source and routes alarms to 20+ notification channels with AI-assisted triage.

View details
95
Repo Health
77
Technical
67
Dependency
Built with
Go 98%
Updated 1 weeks ago
Go
79%
Apache 2.0

OpenMeter

Developer Tools · Invoicing Finance

2,401

Open-source metering and billing engine for AI, agentic, and DevTool monetization — ingest usage events in real time and turn them into accurate invoices automatically.

View details
87
Repo Health
81
Technical
66
Dependency
Built with
Go 79%
TypeScript 16%
Updated 1 weeks ago
TypeScript
51%
ZLIB

Portainer

Devops

38,707

A lightweight, open-source web UI that puts Docker, Kubernetes, and Podman management within reach of any team—no CLI expertise required.

View details
93
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 51%
Go 38%
Updated 1 weeks ago
Go
40%
Apache 2.0

Rill

Analytics · Data Engineering

2,962

The fastest BI tool for humans and agents — define metrics, models, and dashboards as code and query them instantly on ClickHouse or DuckDB.

View details
88
Repo Health
88
Technical
64
Dependency
Built with
Go 40%
TypeScript 38%
Svelte 21%
Updated 6 days ago
Go
54%
GPL 3.0

SafeLine

Security

22,923

Self-hosted WAF with a custom semantic detection engine and ML-powered threat analysis that blocks web attacks without cloud dependency.

View details
87
Repo Health
72
Technical
69
Dependency
Built with
Go 54%
C++ 19%
Updated 1 weeks ago
Go
99%
MIT

temporal

Automation · Devops

23,948

Open-source durable execution platform that keeps mission-critical workflows running through any failure, automatically.

View details
92
Repo Health
85
Technical
67
Dependency
Built with
Go 99%
Updated 6 days ago
Go
95%
Apache 2.0

TiDB

AI Development · Databases

40,672

AI-Native Distributed SQL Database for Agentic Workloads

View details
97
Repo Health
66
Technical
68
Dependency
Built with
Go 95%
Updated 1 weeks ago
Go
66%
AGPL 3.0

Vikunja

Project Management

5,833

Self-hosted task management with natural-language quick-add, multiple views, and a fully documented REST API — your tasks, your infrastructure, zero lock-in.

View details
86
Repo Health
81
Technical
65
Dependency
Built with
Go 66%
TypeScript 24%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers