A robust cron job manager built on robfig/cron with enhanced features for production use.
- Context-aware jobs: func(ctx context.Context) error signature
- Built-in UI: Web interface for monitoring and control
- Manual execution: API endpoints for on-demand job runs
- Middleware support: Extensible pipeline for job processing
- Enhanced state tracking: Detailed job status monitoring
- Schedule visualization: Tools for schedule inspection
WithLoggerTraditional logging via Printf function.WithSLogLogs job execution via slog.WithSentryReports errors to Sentry (includes panic recovery).WithRecoverRecovers from panics (alternative to Sentry).WithDevelMarks development environment in context.WithSkipActivePrevents parallel execution of the same job.WithMaintenanceEnsures exclusive execution for maintenance jobs.WithMetricsTracks execution metrics (count, duration, active jobs).
Run curl http://localhost:2112/debug/cron for schedule.
cron | schedule | next | state
cron=f1 | * * * * * | (starts in 16.505033s) | idle
cron=f2 | * * * * * | (starts in 16.505028s) | idle
cron=f5 | | never | disabled
cron=f3 (maintenance) | */2 * * * * | (starts in 16.505025s) | idle
Run curl -L http://localhost:2112/debug/cron?start=<name> for manual job run.
Run curl -H 'Accept: application/json' http://localhost:2112/debug/cron for json output.
app_cron_evaluated_total– total processed jobs by state.app_cron_active– active running jobs.app_cron_evaluated_duration_seconds– summary metric with durations.
Please see examples/main.go for basic usage.
m := cron.NewManager()
m.Use(
cron.WithMetrics("test"),
cron.WithDevel(false),
cron.WithSLog(sl),
cron.WithLogger(log.Printf, "test-run"),
cron.WithMaintenance(log.Printf),
cron.WithSkipActive(),
cron.WithRecover(), // recover() inside
cron.WithSentry(), // recover() inside
)
// add simple funcs
m.AddFunc("f1", "* * * * *", newTask("f1"))
m.AddFunc("f2", "* * * * *", newTask("f2"))
m.AddFunc("f5", "", newTask("f5"))
m.AddMaintenanceFunc("f3", "*/2 * * * *", newTask("f3m"))
// run cron
if err := m.Run(ctx); err != nil {
log.Fatal(err)
}
http.HandleFunc("/debug/cron", m.Handler)