| 1 | // Package chronos is an in-process, cron-like scheduler. It exists to |
| 2 | // run recurring work inside a single Go program without an external |
| 3 | // scheduler or a separate process: jobs share one supervisor, one |
| 4 | // concurrency budget, and the program's own context for shutdown. |
| 5 | // |
| 6 | // A job pairs a schedule with a [JobFunc]. Build one of two ways: |
| 7 | // |
| 8 | // - [NewCron] parses a cron spec (5- or 6-field, an @-macro, or |
| 9 | // "@every <dur>"). |
| 10 | // - [NewEvery] fires on a fixed interval expressed as one or more |
| 11 | // [Span] values, which are calendar-aware: months and years respect |
| 12 | // month lengths, leap years, and daylight saving. |
| 13 | // |
| 14 | // Refine a job with chained builders before registering it: [Job.Delta] |
| 15 | // (per-fire jitter), [Job.Timeout] (cancel a slow run), [Job.SlotWait] |
| 16 | // (how long to wait for a concurrency slot), [Job.Name], and |
| 17 | // [Job.OnOverlap] ([OverlapSkip] or [OverlapAllow]). |
| 18 | // |
| 19 | // A [Supervisor] owns the jobs and their lifecycle. Build it with [New] |
| 20 | // and [Option]s, register jobs with [Supervisor.Add], then call |
| 21 | // [Supervisor.Start] with a context and [Supervisor.Stop] to drain. The |
| 22 | // supervisor bounds total concurrency across all jobs with |
| 23 | // [WithMaxInflight]: when the budget is full, [WithSlotWait] (or the |
| 24 | // per-job [Job.SlotWait]) decides whether a fire sheds, waits, or waits |
| 25 | // then sheds. |
| 26 | // |
| 27 | // Inside a run, the [JobFunc] receives a [ChronosContext]. It embeds the |
| 28 | // run's [context.Context] (cancelled on timeout or shutdown) and lets the |
| 29 | // job register sibling jobs with [ChronosContext.Add] or retire itself |
| 30 | // with [ChronosContext.Deactivate] without cancelling the current run. |
| 31 | package chronos |
| 32 | |