scheduler

package
v0.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package scheduler implements a simple scheduler that triggers the next item when its due time is reached based on the list of upcoming items.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TriggerNames

func TriggerNames(toTrigger []Item) string

TriggerNames returns a human-readable description of the items that are about to be triggered.

Types

type GetItemsFunc

type GetItemsFunc func(ctx context.Context, now time.Time) []Item

GetItemsFunc is a callback that returns items for the scheduler to consider.

type Item

type Item struct {
	Description string
	NextTime    time.Time
	Trigger     func()
}

Item describes an item that can be scheduled with a function that is invoked the next time the item is due.

type Options

type Options struct {
	TimeNow        func() time.Time
	Debug          bool
	RefreshChannel chan string
}

Options the scheduler.

type Scheduler

type Scheduler struct {
	TimeNow func() time.Time
	Debug   bool
	// contains filtered or unexported fields
}

Scheduler manages triggering of arbitrary events by periodically determining the first of a set of upcoming events and waiting until it's due and invoking the trigger function.

func Start

func Start(ctx context.Context, getItems GetItemsFunc, opts Options) *Scheduler

Start runs a new scheduler that will call getItems() to get the list of items to schedule.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop stops the scheduler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL