scheduler

package
v0.0.0-...-453cd44 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: GPL-3.0 Imports: 10 Imported by: 15

Documentation

Overview

Package scheduler implements a distributed consensus scheduler with etcd.

Index

Constants

View Source
const (
	// DefaultSessionTTL is the number of seconds to wait before a dead or
	// unresponsive host is removed from the scheduled pool.
	DefaultSessionTTL = 10 // seconds

	// DefaultMaxCount is the maximum number of hosts to schedule on if not
	// specified.
	DefaultMaxCount = 1 // TODO: what is the logical value to choose? +Inf?

)

Variables

View Source
var ErrEndOfResults = errors.New("scheduler: end of results")

ErrEndOfResults is a sentinel that represents no more results will be coming.

Functions

func Register

func Register(name string, fn func() Strategy)

Register takes a func and its name and makes it available for use. It is commonly called in the init() method of the func at program startup. There is no matching Unregister function.

Types

type Option

type Option func(*schedulerOptions)

Option is a type that can be used to configure the scheduler.

func Debug

func Debug(debug bool) Option

Debug specifies whether we should run in debug mode or not.

func HostsFilter

func HostsFilter(hosts []string) Option

HostsFilter specifies a manual list of hosts, to use as a subset of whatever was auto-discovered. XXX: think more about this idea...

func Logf

func Logf(logf func(format string, v ...interface{})) Option

Logf passes a logger function that we can use if so desired.

func MaxCount

func MaxCount(maxCount int) Option

MaxCount is the maximum number of hosts that should get simultaneously scheduled.

func ReuseLease

func ReuseLease(reuseLease bool) Option

ReuseLease specifies whether we should try and re-use the lease between runs. Ordinarily it would get discarded with each new version (deploy) of the code.

func SessionTTL

func SessionTTL(sessionTTL int) Option

SessionTTL is the amount of time to delay before expiring a key on abrupt host disconnect of if ReuseLease is true.

func StrategyKind

func StrategyKind(strategy string) Option

StrategyKind sets the scheduler strategy used.

type Result

type Result struct {
	// contains filtered or unexported fields
}

Result is what is returned when you request a scheduler. You can call methods on it, and it stores the necessary state while you're running. When one of these is produced, the scheduler has already kicked off running for you automatically.

func Schedule

func Schedule(client *etcd.Client, path string, hostname string, opts ...Option) (*Result, error)

Schedule returns a scheduler result which can be queried with it's available methods. This automatically causes different etcd clients sharing the same path to discover each other and be part of the scheduled set. On close the keys expire and will get removed from the scheduled set. Different options can be passed in to customize the behaviour. Hostname represents the unique identifier for the caller. The behaviour is undefined if this is run more than once with the same path and hostname simultaneously.

func (*Result) Next

func (obj *Result) Next(ctx context.Context) ([]string, error)

Next returns the next output from the scheduler when it changes. This blocks until a new value is available, which is why you may wish to use a context to cancel any read from this. It returns ErrEndOfResults if the scheduler shuts down.

func (*Result) Shutdown

func (obj *Result) Shutdown()

Shutdown causes everything to clean up. We no longer need the scheduler. TODO: should this be named Close() instead? Should it return an error?

type Strategy

type Strategy interface {
	Schedule(hostnames map[string]string, opts *schedulerOptions) ([]string, error)
}

Strategy represents the methods a scheduler strategy must implement.

Jump to

Keyboard shortcuts

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