MCPcopy Index your code
hub / github.com/flant/shell-operator / NewTasksQueue

Function NewTasksQueue

pkg/task/queue/task_queue.go:180–208  ·  view source on GitHub ↗

NewTasksQueue creates a new TaskQueue with the provided options

(name string, metricStorage metricsstorage.Storage, opts ...TaskQueueOption)

Source from the content-addressed store, hash-verified

178
179// NewTasksQueue creates a new TaskQueue with the provided options
180func NewTasksQueue(name string, metricStorage metricsstorage.Storage, opts ...TaskQueueOption) *TaskQueue {
181 q := &TaskQueue{
182 Name: name,
183 storage: newTaskStorage(),
184 // Default timings
185 WaitLoopCheckInterval: DefaultWaitLoopCheckInterval,
186 DelayOnQueueIsEmpty: DefaultDelayOnQueueIsEmpty,
187 DelayOnRepeat: DefaultDelayOnRepeat,
188 ExponentialBackoffFn: func(failureCount int) time.Duration {
189 return exponential_backoff.CalculateDelay(DefaultInitialDelayOnFailedTask, failureCount)
190 },
191 logger: log.NewLogger().Named("task_queue").Named(name),
192 // Pre-allocate buffers
193 contextBuffer: make([]bindingcontext.BindingContext, 0, 128),
194 monitorIDBuffer: make([]string, 0, 128),
195 groupBuffer: make(map[string]*compactionGroup, 32),
196 metricStorage: metricStorage,
197 status: NewTaskQueueStatus(),
198 }
199
200 // Apply all options
201 for _, opt := range opts {
202 opt(q)
203 }
204
205 q.queueTasksCounter = NewTaskCounter(q.Name, q.compactableTypes, q.metricStorage)
206
207 return q
208}
209
210func (q *TaskQueue) getCompactionGroup() *compactionGroup {
211 return compactionGroupPool.Get().(*compactionGroup)

Callers 6

newBenchmarkTasksQueueFunction · 0.85
TestConcurrentOperationsFunction · 0.85
NewNamedQueueMethod · 0.85

Calls 4

CalculateDelayFunction · 0.92
newTaskStorageFunction · 0.85
NewTaskQueueStatusFunction · 0.85
NewTaskCounterFunction · 0.85