Documentation
¶
Index ¶
- Constants
- Variables
- func NewClient(namespace string, client *etcd.Client) metafora.Client
- func NewEtcdCoordinator(nodeID, namespace string, client *etcd.Client) metafora.Coordinator
- func NewFairBalancer(nodeid, namespace string, client *etcd.Client) metafora.Balancer
- type EtcdCoordinator
- func (ec *EtcdCoordinator) Claim(taskID string) bool
- func (ec *EtcdCoordinator) Close()
- func (ec *EtcdCoordinator) Command() (metafora.Command, error)
- func (ec *EtcdCoordinator) Done(taskID string)
- func (ec *EtcdCoordinator) Init(cordCtx metafora.CoordinatorContext) error
- func (ec *EtcdCoordinator) Release(taskID string)
- func (ec *EtcdCoordinator) Watch() (taskID string, err error)
Constants ¶
const ( TasksPath = "tasks" NodesPath = "nodes" CommandsPath = "commands" MetadataKey = "_metafora" // _{KEYs} are hidden files, so this will not trigger our watches OwnerMarker = "owner" ForeverTTL = 0 //Ref: https://github.com/coreos/go-etcd/blob/e10c58ee110f54c2f385ac99764e8a7ca4cb13df/etcd/requests.go#L356 //Etcd Error codes are passed directly through go-etcd from the http response, //So to find the error codes use this ref: // https://github.com/coreos/etcd/blob/master/error/error.go#L67 EcodeKeyNotFound = 100 EcodeNodeExist = 105 EcodeExpiredIndex = 401 // The event in requested index is outdated and cleared )
Variables ¶
var ( ClaimTTL uint64 = 120 // seconds DefaultNodePathTTL uint64 = 20 // seconds )
Functions ¶
func NewEtcdCoordinator ¶
func NewEtcdCoordinator(nodeID, namespace string, client *etcd.Client) metafora.Coordinator
NewEtcdCoordinator creates a new Metafora Coordinator implementation using etcd as the broker. If no node ID is specified, a unique one will be generated.
Coordinator methods will be called by the core Metafora Consumer. Calling Init, Close, etc. from your own code will lead to undefined behavior.
Types ¶
type EtcdCoordinator ¶
type EtcdCoordinator struct {
Client *etcd.Client
ClaimTTL uint64 // seconds
NodeID string
// contains filtered or unexported fields
}
func (*EtcdCoordinator) Claim ¶
func (ec *EtcdCoordinator) Claim(taskID string) bool
Claim is called by the Consumer when a Balancer has determined that a task ID can be claimed. Claim returns false if another consumer has already claimed the ID.
func (*EtcdCoordinator) Close ¶
func (ec *EtcdCoordinator) Close()
Close stops the coordinator and causes blocking Watch and Command methods to return zero values.
func (*EtcdCoordinator) Command ¶
func (ec *EtcdCoordinator) Command() (metafora.Command, error)
Command blocks until a command for this node is received from the broker by the coordinator.
func (*EtcdCoordinator) Done ¶
func (ec *EtcdCoordinator) Done(taskID string)
Done deletes the task.
func (*EtcdCoordinator) Init ¶
func (ec *EtcdCoordinator) Init(cordCtx metafora.CoordinatorContext) error
Init is called once by the consumer to provide a Logger to Coordinator implementations.
func (*EtcdCoordinator) Release ¶
func (ec *EtcdCoordinator) Release(taskID string)
Release deletes the claim file.
func (*EtcdCoordinator) Watch ¶
func (ec *EtcdCoordinator) Watch() (taskID string, err error)
Watch will do a blocking etcd watch on taskPath until a claimable task is found or Close() is called.
Watch will return ("", nil) if the coordinator is closed.