Documentation
¶
Index ¶
- Constants
- func ShouldRunLocalHour(tz string, hour int) bool
- func ShouldRunLocalTime(tz string, hour, minute int) bool
- type Job
- type Option
- type Scheduler
- func (s *Scheduler) Active() int64
- func (s *Scheduler) Add(id string, slot int, job Job) error
- func (s *Scheduler) AddMany(id string, slots []int, job Job) error
- func (s *Scheduler) Idled() <-chan struct{}
- func (s *Scheduler) RunOnce(ctx context.Context, id string, job Job) bool
- func (s *Scheduler) Start(ctx context.Context)
Constants ¶
const ( DefaultShutdownTimeout = 60 * time.Second DefaultJobTimeout = time.Hour )
Variables ¶
This section is empty.
Functions ¶
func ShouldRunLocalHour ¶ added in v1.6.0
func ShouldRunLocalTime ¶ added in v1.6.4
ShouldRunLocalTime returns true if the local time in tzName matches hour:minute exactly.
Types ¶
type Option ¶ added in v1.6.0
type Option func(*Scheduler)
Option configures the Scheduler.
func WithJobTimeout ¶ added in v1.6.0
WithJobTimeout sets the default per-job timeout if ctx has no deadline.
func WithLogger ¶ added in v1.6.0
WithLogger sets the logger. Nil => Noop logger.
func WithShutdownTimeout ¶ added in v1.6.0
WithShutdownTimeout sets how long Start() waits for jobs to drain after ctx cancel.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler runs Jobs on a fixed tick schedule. It also supports one-shot jobs and prevents concurrent runs of the same logical task (by ID). For each distinct id, only one instance may run at the same time.
func (*Scheduler) Add ¶
Add registers a recurring job at the given slot (must be a multiple of granularity). id must be unique for each logical task; concurrent duplicates will be skipped.
func (*Scheduler) AddMany ¶
AddMany registers the same job on multiple slots. IDs must be distinct per logical task.
func (*Scheduler) Idled ¶ added in v1.6.2
func (s *Scheduler) Idled() <-chan struct{}
Idled returns a channel that receives a value whenever the scheduler drains all current jobs. Consumers should check Active() after receiving since new jobs may already have started.