api

package
v0.0.2-0...-4ce78c8 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodePayload

func EncodePayload(m model.MessageBody) ([]byte, error)

EncodePayload encodes a process message into a payload

Types

type WeightedItem

type WeightedItem interface {
	// Weight returns the weight of this item
	Weight() int64
	// Type returns the type of this item
	Type() string
}

WeightedItem is an item that has a type and weight that can be added to a WeightedQueue

type WeightedQueue

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

WeightedQueue is a queue of WeightedItems.

The queue is configured with a maximum size (the maximum number of elements allowed in the queue) as well as a maximum weight. If adding an item to the queue would violate either the max weight or max size, earlier items are purged from the queue until there is room for the newest item.

Items added to the queue have a weight and type. When purging existing items to make room for new, items of the same type being added will be removed first before moving on to other types.

func NewWeightedQueue

func NewWeightedQueue(maxSize int, maxWeight int64) *WeightedQueue

NewWeightedQueue returns a new WeightedQueue with the given maximum size & weight

func (*WeightedQueue) Add

func (q *WeightedQueue) Add(item WeightedItem)

Add adds the item to the queue.

func (*WeightedQueue) Len

func (q *WeightedQueue) Len() int

Len returns the number of items in the queue

func (*WeightedQueue) Poll

func (q *WeightedQueue) Poll(exit chan struct{}) (WeightedItem, bool)

Poll retrieves the head of the queue or blocks until an item is available. The provided exit channel can be closed to interrupt the blocking operation. Returns the head of the queue and true or nil, false if the poll was interrupted by the closing of the exit channel

func (*WeightedQueue) Weight

func (q *WeightedQueue) Weight() int64

Weight returns the current weight of the queue

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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