queue

package
v0.0.0-...-2187358 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxAggregatableQueueItems = 20
)

Variables

View Source
var (
	ErrNoItemsInQueue       = errors.New("there are no items in the queue")
	ErrNoSuchQueueStr       = "no queue found with id %v"
	ErrMaxQueueSizeExceeded = fmt.Errorf("you cannot store more than %v items in your queue.", MaxAggregatableQueueItems)
)

Functions

This section is empty.

Types

type AggregatableQueue

type AggregatableQueue interface {
	api.ApiCodec
	QueueItem
	ReorderableQueue
}

AggregatableQueue is a queue that can be aggregated as a QueueItem and implements ReorderableQueue

func NewAggregatableQueue

func NewAggregatableQueue(id string) AggregatableQueue

type AggregatableQueueSchema

type AggregatableQueueSchema struct {
	ReorderableQueue
	QueueItem
}

AggregatableQueueSchema implements AggregatableQueue,

func (*AggregatableQueueSchema) Push

func (q *AggregatableQueueSchema) Push(item QueueItem) error

func (*AggregatableQueueSchema) Serialize

func (q *AggregatableQueueSchema) Serialize() ([]byte, error)

type Queue

type Queue interface {
	// Clear empties all QueueItems in the queue
	Clear()
	// DeleteItem deletes the given QueueItem from the queue.
	// Returns an error if QueueItem is not found
	DeleteItem(QueueItem) error
	// List returns a slice of aggregated QueueItems
	List() []QueueItem
	// Pop pops the first QueueItem in the queue.
	// Returns the popped QueueItem or an error.
	Pop() (QueueItem, error)
	// Push appends a QueueItem to the queue
	// a new one is created with the given id.
	// Returns error if item could not be pushed.
	Push(QueueItem) error
	// Set replaces its internal list of QueueItems with a received slice of QueueItems
	Set([]QueueItem)
	// Size returns the total amount of QueueItems in the queue
	Size() int
	// Visit visits each QueueItem aggregated by the RoundRobinQueue and
	// passes each item to the RoundRobinQueueVisitor.
	Visit(QueueVisitor)
}

Queue performs collection operations on a fifo structure

func NewQueue

func NewQueue() Queue

type QueueHandler

type QueueHandler interface {
	// Clear calls the handled queue's Clear method
	Clear()
	// PopFromQueue receives an AggregatableQueue
	// and a QueueItem belonging to the AggregatableQueue and
	// attempts to pop that item from the AggregatableQueue.
	// If at least one parent ref is received, it is removed
	// from the list of the passed QueueItem's parentRef list.
	PopFromQueue(AggregatableQueue, QueueItem) error
	// PushToQueue receives an AggregatableQueue and a QueueItem
	// and pushes the given QueueItem to the AggregatableQueue.
	PushToQueue(AggregatableQueue, QueueItem) error
	// GetQueue returns the handled queue
	Queue() Queue
}

TODO: break this file out into its own "queue" package have a separate file for the controller.

func NewQueueHandler

func NewQueueHandler(queue Queue) QueueHandler

type QueueHandlerSpec

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

QueueHandlerSpec implements QueueHandler

func (*QueueHandlerSpec) Clear

func (h *QueueHandlerSpec) Clear()

func (*QueueHandlerSpec) PopFromQueue

func (h *QueueHandlerSpec) PopFromQueue(aggQueue AggregatableQueue, item QueueItem) error

func (*QueueHandlerSpec) PushToQueue

func (h *QueueHandlerSpec) PushToQueue(aggQueue AggregatableQueue, item QueueItem) error

func (*QueueHandlerSpec) Queue

func (h *QueueHandlerSpec) Queue() Queue

type QueueItem

type QueueItem interface {
	UUID() string
}

QueueItem represents internal queue storage with a unique identifier

func NewQueueItem

func NewQueueItem(id string) QueueItem

type QueueItemSchema

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

QueueItemSchema implements Queue and QueueItem

func (*QueueItemSchema) UUID

func (qi *QueueItemSchema) UUID() string

type QueueSchema

type QueueSchema struct {
	Items []QueueItem `json:"items"`
	// contains filtered or unexported fields
}

QueueSchema implements Queue

func (*QueueSchema) Clear

func (q *QueueSchema) Clear()

func (*QueueSchema) DeleteItem

func (q *QueueSchema) DeleteItem(item QueueItem) error

func (*QueueSchema) List

func (q *QueueSchema) List() []QueueItem

func (*QueueSchema) Pop

func (q *QueueSchema) Pop() (QueueItem, error)

func (*QueueSchema) Push

func (q *QueueSchema) Push(item QueueItem) error

func (*QueueSchema) Set

func (q *QueueSchema) Set(items []QueueItem)

func (*QueueSchema) Size

func (q *QueueSchema) Size() int

func (*QueueSchema) Visit

func (q *QueueSchema) Visit(visitor QueueVisitor)

type QueueVisitor

type QueueVisitor func(QueueItem)

type ReorderableQueue

type ReorderableQueue interface {
	Queue

	// Lock locks the ReorderableQueue mutex
	Lock()
	// Unlock unlocks the ReorderableQueue mutex
	Unlock()
	// Reorder is a concurrency-safe method that receives an array of integers
	// representing the new index order of QueueItems. If the length N of new
	// indices is greater than total amount of QueueItems, the remaining new
	// indices are ignored. If the length N of new indices is less than total
	// QueueItems, then a total of N QueueItems will be re-ordered. The remaining
	// QueueItems are not affected and are pushed (in their original order) after
	// the newly affected affected items.
	//
	// Example:
	//
	//   Existing queue order: [A, B, C, D]
	//   New queue order:      [3, 1]
	//   Resulting order:      [D, B, A, C]
	//
	//   Existing queue order: [A, B, C, D]
	//   New queue order:      [3, 1, 2, 0]
	//   Resulting order:      [D, B, C, A]
	//
	// Returns an error if a list of new indices contains duplicate indices, or if any
	// provided index is greater than the size of the Queue.
	Reorder([]int) error
}

func NewReorderableQueue

func NewReorderableQueue() ReorderableQueue

type ReorderableQueueSchema

type ReorderableQueueSchema struct {
	Queue
	// contains filtered or unexported fields
}

ReorderableQueueSchema implements ReorderableQueue

func (*ReorderableQueueSchema) Lock

func (q *ReorderableQueueSchema) Lock()

func (*ReorderableQueueSchema) Reorder

func (q *ReorderableQueueSchema) Reorder(newOrder []int) error

func (*ReorderableQueueSchema) Unlock

func (q *ReorderableQueueSchema) Unlock()

type RoundRobinQueue

type RoundRobinQueue interface {
	api.ApiCodec
	ReorderableQueue

	// CurrentIndex returns the current round-robin index
	CurrentIndex() int
	// DeleteFromQueue receives an aggregated queue within the round-robin
	// queue and attempts to delete a QueueItem from it.
	DeleteFromQueue(Queue, QueueItem) error
	// Next fetches the Queue at the current round-robin
	// index and pops its first QueueItem.
	// If popping a QueueItem results in an empty Queue,
	// that Queue is removed from the aggregated Queues.
	// Returns the popped QueueItem or an error.
	Next() (QueueItem, error)
	// PeekItems returns a slice containing the first item
	// from each aggregated QueueItem in the queue.
	PeekItems() []QueueItem
}

RoundRobinQueue aggregates a collection of Queues and steps through them in fifo order.

func NewRoundRobinQueue

func NewRoundRobinQueue() RoundRobinQueue

type RoundRobinQueueSchema

type RoundRobinQueueSchema struct {
	ReorderableQueue
	// contains filtered or unexported fields
}

RoundRobinQueueSchema implements RoundRobinQueue

func (*RoundRobinQueueSchema) Clear

func (q *RoundRobinQueueSchema) Clear()

func (*RoundRobinQueueSchema) CurrentIndex

func (q *RoundRobinQueueSchema) CurrentIndex() int

func (*RoundRobinQueueSchema) DeleteFromQueue

func (q *RoundRobinQueueSchema) DeleteFromQueue(queue Queue, qItem QueueItem) error

func (*RoundRobinQueueSchema) DeleteItem

func (q *RoundRobinQueueSchema) DeleteItem(queue QueueItem) error

func (*RoundRobinQueueSchema) Next

func (q *RoundRobinQueueSchema) Next() (QueueItem, error)

func (*RoundRobinQueueSchema) PeekItems

func (q *RoundRobinQueueSchema) PeekItems() []QueueItem

func (*RoundRobinQueueSchema) Push

func (q *RoundRobinQueueSchema) Push(item QueueItem) error

func (*RoundRobinQueueSchema) Serialize

func (q *RoundRobinQueueSchema) Serialize() ([]byte, error)

func (*RoundRobinQueueSchema) Visit

func (q *RoundRobinQueueSchema) Visit(visitor QueueVisitor)

type SerializableQueue

type SerializableQueue interface {
	Queue
	api.ApiCodec
}

SerializableQueue represents a queue that can be handled by a rest client

Jump to

Keyboard shortcuts

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