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() (WeightedItem, bool)
Poll retrieves the head of the queue or blocks until an item is available or the WeightedQueue is stopped. Returns the head of the queue and true or nil, false if the WeightedQueue is stopped.
func (*WeightedQueue) Stop ¶
func (q *WeightedQueue) Stop()
Stop stops the WeightedQueue instance. Any calls to Poll concurrent with or after the call to Stop will return (nil, false) immediately.
func (*WeightedQueue) Weight ¶
func (q *WeightedQueue) Weight() int64
Weight returns the current weight of the queue