chief

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

README

Chief

GoDoc

Package github.com/olomix/chief elects a leader using etcd and runs a pool of workers on leader. If leadership is lost, workers shut down and run on another instance that takes leadership.

Documentation

Overview

Package github.com/olomix/chief elects a leader using etcd and runs a pool of workers on leader. If leadership is lost, workers shut down and run on another instance that takes leadership.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

type Controller interface {
	// Register a Worker. If leadership is already taken, worker starts
	// immediately. Otherwise, it will be start when controller will be
	// elected as leader.
	Register(worker Worker)

	// Close stops all workers and resign leadership.
	Close()
}

func NewController

func NewController(cli *clientv3.Client, token string) Controller

NewController returns a new Controller from etcd client.

It runs worker goroutine that should be stopped using Controller.Stop method.

token is a unique identifier of election participants group. Only one of participants would be elected in a group, identified by token on current etcd cluster.

type Worker

type Worker interface {
	// Start starts a worker. Method is called synchronously, so if there
	// is a long job to be done, it should be run as goroutine inside Start
	// method.
	Start()

	// Stop should stop all goroutines started by Start method. And clean
	// all resources.
	Stop()
}

Worker represents a worker coroutine that can be registered with Controller.Register. When controller instance become a leader in an etcd cluster, it runs worker using Worker.Start method. Start method should exit immediately. If it needs to run gorouting, it should be run inside Start method and return as soon as possible.

If leadership is lost as a result of etcd cluster becomes broken or connectivity issues, worker will be stopped with a Stop method.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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