package scheduler
import "github.com/purpleidea/mgmt/etcd/scheduler"
Package scheduler implements a distributed consensus scheduler with etcd.
Index ¶
- Constants
- Variables
- func Register(name string, fn func() Strategy)
- type Option
- func Debug(debug bool) Option
- func HostsFilter(hosts []string) Option
- func Logf(logf func(format string, v ...interface{})) Option
- func MaxCount(maxCount int) Option
- func ReuseLease(reuseLease bool) Option
- func SessionTTL(sessionTTL int) Option
- func StrategyKind(strategy string) Option
- type Result
- func Schedule(client *etcd.Client, path string, hostname string, opts ...Option) (*Result, error)
- func (obj *Result) Next(ctx context.Context) ([]string, error)
- func (obj *Result) Shutdown()
- type Strategy
Constants ¶
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 ¶
ErrEndOfResults is a sentinel that represents no more results will be coming.
Functions ¶
func Register ¶
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 ¶
Debug specifies whether we should run in debug mode or not.
func HostsFilter ¶
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 ¶
Logf passes a logger function that we can use if so desired.
func MaxCount ¶
MaxCount is the maximum number of hosts that should get simultaneously scheduled.
func ReuseLease ¶
ReuseLease specifies whether we should try and reuse the lease between runs. Ordinarily it would get discarded with each new version (deploy) of the code.
func SessionTTL ¶
SessionTTL is the amount of time to delay before expiring a key on abrupt host disconnect of if ReuseLease is true.
func StrategyKind ¶
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 ¶
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 ¶
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.
Source Files ¶
alphastrategy.go options.go rrstrategy.go scheduler.go strategy.go
- Version
- v0.0.0-20250322185616-c50a578426f1 (latest)
- Published
- Mar 22, 2025
- Platform
- linux/amd64
- Imports
- 10 packages
- Last checked
- 4 days ago –
Tools for package owners.