@@ -43,25 +43,28 @@ func main() {
4343 ctx , stop := signal.NotifyContext (context.Background (), os.Interrupt )
4444 defer stop ()
4545
46- c.Start (ctx )
46+ c.Start (context. Background () )
4747
4848 <- ctx.Done ()
49- c.Stop (context.Background ())
49+ c.Shutdown (context.Background ())
5050}
5151```
5252
5353## Features
5454
5555- ** Standard 5-field cron expressions** (minute, hour, dom, month, dow) plus
5656 optional seconds via ` WithSeconds() ` .
57- - ** ` context. Context` throughout ** — ` Start ` , ` Run ` , ` Stop ` , and every ` Job `
58- receive a context for cancellation and deadlines.
57+ - ** Context-aware lifecycle ** — ` Start ` , ` Run ` , ` Stop ` , ` Shutdown ` , and every
58+ ` Job ` participate in cancellation and deadlines.
5959- ** ` log/slog ` logging** — structured, leveled logging out of the box. Default
6060 level is ` slog.LevelWarn ` to keep the scheduler quiet.
6161- ** ` Clock ` interface** — inject a fake clock via ` WithClock ` for deterministic,
6262 zero-` time.Sleep ` tests.
6363- ** Job wrappers** — ` Recover ` , ` SkipIfStillRunning ` , ` DelayIfStillRunning ` ,
6464 ` Timeout ` , ` MaxConcurrent ` , ` RetryOnError ` , and custom ` JobWrapper ` chains.
65+ - ** Defensive configuration** — malformed ` TZ= ` / ` CRON_TZ= ` prefixes and
66+ invalid ` @every ` intervals return parse errors; nil ` With* ` options keep
67+ defaults.
6568- ** Named entries** — ` AddNamedFunc ` / ` AddNamedJob ` attach human-readable
6669 labels for logging and observability.
6770- ** Event hooks** — ` WithEventHooks ` for ` OnJobStart ` / ` OnJobComplete `
@@ -98,6 +101,10 @@ func main() {
98101@every 1h30m
99102```
100103
104+ ` @every ` accepts positive ` time.ParseDuration ` values. Durations smaller than a
105+ second still round up to 1 second; ` @every 0s ` and negative durations are
106+ rejected as configuration errors.
107+
101108### Time zones
102109
103110``` go
@@ -106,8 +113,26 @@ cron.New(cron.WithLocation(time.UTC))
106113c.AddFunc (" CRON_TZ=Asia/Tokyo 0 6 * * ?" , myJob)
107114```
108115
116+ Malformed timezone prefixes such as ` CRON_TZ= ` or ` CRON_TZ=UTC ` without a
117+ schedule body return parse errors instead of panicking.
118+
119+ ## Lifecycle
120+
121+ Use ` Start(ctx) ` for a background scheduler and ` Run(ctx) ` for a blocking one.
122+ The context passed to ` Start ` or ` Run ` is also the parent context for every job.
123+
124+ - ` Stop(ctx) ` cancels the scheduler and cancels contexts already handed to
125+ running jobs before waiting for them to return.
126+ - ` Shutdown(ctx) ` stops future scheduling and waits for running jobs to finish
127+ without cancelling their contexts.
128+ - If the ` Start ` / ` Run ` context is cancelled directly, both the scheduler and
129+ job contexts are cancelled.
130+
109131## Job wrappers / Chain
110132
133+ Panic recovery is available but not enabled by default. Install ` Recover `
134+ explicitly if you want panics turned into logged ` ErrPanic ` errors:
135+
111136``` go
112137c := cron.New (cron.WithChain (
113138 cron.Recover (logger),
@@ -186,6 +211,11 @@ c := cron.New(cron.WithClock(fakeClock))
186211
187212See ` clock.go ` for the interface definition.
188213
214+ ## Option defaults
215+
216+ Passing ` nil ` to ` WithLocation ` , ` WithParser ` , ` WithLogger ` , or ` WithClock `
217+ keeps the package default instead of leaving the scheduler in an invalid state.
218+
189219## Migration from robfig/cron/v3
190220
191221See [ MIGRATION.md] ( MIGRATION.md ) for a step-by-step upgrade guide.
0 commit comments