{"modulePath":"github.com/mycontroller-org/server/v2","version":"v2.2.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package queue\n\n## Types\n\n```go\ntype BoundedQueue struct {\n\t// contains filtered or unexported fields\n}\n```\nBoundedQueue implements a producer-consumer exchange similar to a ring buffer queue, where the queue is bounded and if it fills up due to slow consumers, the new items written by the producer force the earliest items to be dropped. The implementation is actually based on channels, with a special Reaper goroutine that wakes up when the queue is full and consumers the items from the top of the queue until its size drops back to maxSize\n\n```go\nfunc NewBoundedQueue(capacity int, onDroppedItem func(item interface{})) *BoundedQueue\n```\nNewBoundedQueue constructs the new queue of specified capacity, and with an optional callback for dropped items (e.g. useful to emit metrics).\n\n```go\nfunc NewBoundedQueueWithRetry(capacity int, onDroppedItem func(item interface{}), retryMaxCount uint32, retryDelay time.Duration) *BoundedQueue\n```\nNewBoundedQueue constructs the new queue of specified capacity, and with an optional callback for dropped items (e.g. useful to emit metrics).\n\n```go\nfunc (q *BoundedQueue) Capacity() int\n```\nCapacity returns capacity of the queue\n\n```go\nfunc (q *BoundedQueue) Produce(item interface{}) bool\n```\nProduce is used by the producer to submit new item to the queue. Returns false in case of queue overflow.\n\n```go\nfunc (q *BoundedQueue) Resize(capacity int) bool\n```\nResize changes the capacity of the queue, returning whether the action was successful\n\n```go\nfunc (q *BoundedQueue) Size() int\n```\nSize returns the current size of the queue\n\n```go\nfunc (q *BoundedQueue) StartConsumers(num int, callback func(item interface{}) error)\n```\nStartConsumers starts a given number of goroutines consuming items from the queue and passing them into the consumer callback.\n\n```go\nfunc (q *BoundedQueue) StartConsumersWithFactory(num int, factory func() Consumer)\n```\nStartConsumersWithFactory creates a given number of consumers consuming items from the queue in separate goroutines.\n\n```go\nfunc (q *BoundedQueue) Stop()\n```\nStop stops all consumers, as well as the length reporter if started, and releases the items channel. It blocks until all consumers have stopped.\n\n```go\nfunc (q *BoundedQueue) StopConsumers()\n```\nStopConsumers stops all the consumers should be started again with StartConsumers func\n\n```go\ntype Consumer interface {\n\tConsume(item interface{}) error\n}\n```\nConsumer consumes data from a bounded queue\n\n```go\ntype ConsumerFunc func(item interface{}) error\n```\nConsumerFunc is an adapter to allow the use of a consume function callback as a Consumer.\n\n```go\nfunc (c ConsumerFunc) Consume(item interface{}) error\n```\nConsume calls c(item)\n\n```go\ntype Queue struct {\n\tName    string\n\tQueue   *BoundedQueue\n\tLimit   int\n\tWorkers int\n\t// contains filtered or unexported fields\n}\n```\nQueue to hold items\n\n```go\nfunc New(logger *zap.Logger, name string, limit int, consumer func(item interface{}) error, workers int) *Queue\n```\nNew returns brandnew queue\n\n```go\nfunc NewWithRetry(logger *zap.Logger, name string, limit int, consumer func(item interface{}) error, workers int, isRetryEnabled bool, maxRetryCount uint32, retryDelay time.Duration) *Queue\n```\nNew returns brandnew queue with retry options\n\n```go\nfunc (q *Queue) Close()\n```\nClose the queue\n\n```go\nfunc (q *Queue) Produce(item interface{}) bool\n```\nProduce adds an item to the queue\n\n```go\nfunc (q *Queue) Size() int\n```\nSize returns current size of the queue\n\n```go\ntype QueueSpec struct {\n\tTopic          string\n\tSubscriptionId int64\n\tQueue          *Queue\n}\n```\nused to hold queue and subscription details\n\n```go\nfunc (qs *QueueSpec) Close()\n```\n\n```go\nfunc (qs *QueueSpec) Produce(item interface{}) bool\n```\n\n```go\nfunc (qs *QueueSpec) Size() int\n```\n\n```go\ntype RetryConfig struct {\n\t// contains filtered or unexported fields\n}\n```\nRetryConfig holds configuration for retrying failed items\n\n","path":"github.com/mycontroller-org/server/v2/pkg/utils/queue","name":"queue","synopsis":"","isRedistributable":true}
