consul

package
v0.0.0-...-fe13f99 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package consul integrates scotty with Consul.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissing indicates that the resource is missing.
	ErrMissing = errors.New("consul: Missing.")
)

Functions

This section is empty.

Types

type Coordinator

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

Coordinator represents scotty's connection with consul

func GetCoordinator

func GetCoordinator(
	namespace string, logger log.Logger) (*Coordinator, error)

The first call to GetCoordinator returns a new coordinator for consul that implements store.Coordinator and uses passed logger. Scotty processes that create their Coordinator instance using the same namespace see each other's activity and compete for leadership when connected to the same consul cluster. Scotty processes that create their Coordinator instances using different namespaces behave as if they are on different consul clusters even if they connect to the same one. They do not see eachother's activity nor do they compete for leadership. Scotty panics if namespace has a slash (/) in it.

Successive calls return the same, already created coordinator ignoring the namespace and logger parameter. Blocking methods of the returned coordinator such as the Lease method write any errors encountered to logger. If logger is nil, blocking methods write errors to stderr. Non blocking methods that return an error do not log error messages. The Consul agent runs on the local machine at port 8500 so no other configuration is needed.

func (*Coordinator) GetPStoreConfig

func (c *Coordinator) GetPStoreConfig() (result string, err error)

GetPStoreConfig gets the current scotty config file. If none exists, returns "", ErrMissing

func (*Coordinator) Lease

func (c *Coordinator) Lease(leaseSpanInSeconds, timeToInclude float64) (
	startTimeInclusive, endTimeExclusive float64)

Lease implements Lease from store.Coordinator

func (*Coordinator) PutPStoreConfig

func (c *Coordinator) PutPStoreConfig(value string) error

PutPStoreConfig stores a new scotty config file

func (*Coordinator) WatchPStoreConfig

func (c *Coordinator) WatchPStoreConfig(done <-chan struct{}) <-chan string

WatchPStoreConfig returns the contents of the scotty config file in returned channel. Each time the config file changes, the returned channel emits the entire contents of the file. If the caller calls WatchPStoreConfig before the config file is created, the returned channel blocks until the config file is created. If the config file already exists when the caller calls WatchPStoreConfig, the returned channel emits the initial contents of the file immediately.

If done is non-nil, the caller can close done to signal that it wants the watch terminated. Termination of the watch closes the returned channel. Termination may not happen until several minutes after the call closes the done channel.

func (*Coordinator) WithStateListener

func (c *Coordinator) WithStateListener(
	listener func(blocked bool)) store.Coordinator

WithStateListener returns a new view to this same Coordinator that monitors state. The Lease method on the returned view calls listener(true) if it must block to acquire or extend the lease. Once it has the lease, it calls listener(false) before returning. The Lease method on the returned view makes no calls to listener if it determines that the current lease is viable and can be returned as is.

Jump to

Keyboard shortcuts

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