Documentation
¶
Overview ¶
Package scheduler runs periodic work off one goroutine and one timer.
Forge and its extensions want a lot of periodic work: health check rounds, metric collection, storage cleanup, compression, cache eviction, lease renewal. Written the obvious way, each of those is its own goroutine parked on its own time.Ticker. That cost is per subsystem and it accumulates with every extension an app installs, so an app is never fully idle: each ticker is a runtime timer that wakes a core to send on a channel nobody was waiting on except one parked goroutine.
A Scheduler holds every job in one heap ordered by next run, so the process arms exactly one timer for the earliest of them and sleeps until then.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Runner ¶
Runner is the work a job does on each run. The context is cancelled when the scheduler stops, so a long job can notice and return.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler runs registered jobs on their intervals.
The zero value is not usable; call New.
func Default ¶
func Default() *Scheduler
Default returns the shared scheduler, starting it on first use.
It has no Stop: it belongs to the process, not to any one app, and it costs one parked goroutine when nothing is registered. Cancel individual jobs with the function Every returns.
func (*Scheduler) Every ¶
Every registers fn to run every interval and returns a function that cancels it. A non-positive interval registers nothing and returns a no-op.
The first run happens one interval from now, matching a ticker.
A job never overlaps itself: if a run is still going when the next one is due, that run is skipped rather than queued. Runs happen on their own goroutines, so a slow job delays only itself.