ringv2

package
v5.10.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: MIT, MIT, MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const MinInterval = 5

Variables

This section is empty.

Functions

func Path

func Path(namespace, subscription string) string

Path returns the canonical path to a ring.

Types

type Event

type Event struct {
	// Type is the type of the event.
	Type EventType

	// Values are the ring items associated with the event. For trigger events,
	// the length of Values will be equal to the results per interval.
	Values []string

	// Err is any error that occurred while processing the event.
	Err error
}

Event represents an event that occurred in a ring. The event can originate from any ring client.

type EventType

type EventType int

EventType is an enum that describes the type of event received by watchers.

const (
	EventError EventType = iota
	EventAdd
	EventRemove
	EventTrigger
	EventClosing
)

func (EventType) String

func (e EventType) String() string

type Pool

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

Pool is a pool of rings. It exists to help users avoid creating too many watchers.

func NewPool

func NewPool(client *clientv3.Client) *Pool

NewPool creates a new Pool.

func (*Pool) Get

func (p *Pool) Get(path string) *Ring

Get gets a ring from the pool.

type Ring

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

func New

func New(client *clientv3.Client, storePath string) *Ring

New creates a new Ring.

func (*Ring) Add

func (r *Ring) Add(ctx context.Context, value string, keepalive int64) (rerr error)

Add adds a new value to the ring. If the value already exists, its keepalive will be reset. Values that are not kept alive will expire and be removed from the ring.

func (*Ring) IsEmpty

func (r *Ring) IsEmpty(ctx context.Context) (bool, error)

IsEmpty returns true if there are no items in the ring.

func (*Ring) Remove

func (r *Ring) Remove(ctx context.Context, value string) error

Remove removes a value from the list. If the value does not exist, nothing happens.

func (*Ring) Watch

func (r *Ring) Watch(ctx context.Context, name string, values, interval int, cron string) <-chan Event

Watch watches the ring for events. The events are sent on the channel that is returned. For each interval duration in seconds, one or more values will be delivered, if there are any values in the ring.

If the underlying etcd watcher fails, then the Event will contain a non-nil error.

If the context is canceled, EventClosing will be sent on the channel, and it will be closed.

The name parameter specifies the name of the watch. Watchers should use unique names when requesting different numbers of values.

The interval parameter sets the interval at which ring items will be delivered, in seconds.

If the cron parameter is not the empty string, the interval parameter will be ignored, and the watcher will deliver values according to the cron schedule.

The values parameter controls how many ring values the event will contain. If the requested number of values is greater than the number of items in the values will contain repetitions in order to satisfy the request.

Jump to

Keyboard shortcuts

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