failover

package
v0.4.20 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PASSIVE   status = -1
	UNDEFINED status = 0
	ACTIVE    status = 1
)
View Source
const Label = "github.com.pace.bricks.activepassive"

Variables

This section is empty.

Functions

This section is empty.

Types

type ActivePassive

type ActivePassive struct {
	// OnActive will be called in case the current processes
	// is elected to be the active one
	OnActive func()

	// OnPassive will be called in case the current process is
	// the passive one
	OnPassive func()

	// OnStop is called after the ActivePassive process stops
	OnStop func()
	// contains filtered or unexported fields
}

ActivePassive implements a failover mechanism that allows to deploy a service multiple times but ony one will accept traffic by using the label selector of kubernetes. In order to determine the active, a lock needs to be hold in redis. Hocks can be passed to handle the case of becoming the active or passive. The readiness probe will report the state (ACTIVE/PASSIVE) of each of the members in the cluster.

func NewActivePassive

func NewActivePassive(clusterName string, timeToFailover time.Duration, client *redis.Client) (*ActivePassive, error)

NewActivePassive creates a new active passive cluster identified by the name, the time to failover determines the frequency of checks performed against the redis to keep the active state. NOTE: creating multiple ActivePassive in one processes is not working correctly as there is only one readiness probe.

func (*ActivePassive) Handler

func (a *ActivePassive) Handler(w http.ResponseWriter, r *http.Request)

Handler implements the readiness http endpoint

func (*ActivePassive) Run

func (a *ActivePassive) Run(ctx context.Context) error

Run registers the readiness probe and calls the OnActive and OnPassive callbacks in case the election toke place. Will handle panic safely and therefore can be directly called with go.

func (*ActivePassive) Stop

func (a *ActivePassive) Stop()

Stop stops acting as a passive or active member.

Jump to

Keyboard shortcuts

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