NewTasksQueue creates a new TaskQueue with the provided options
(name string, metricStorage metricsstorage.Storage, opts ...TaskQueueOption)
| 178 | |
| 179 | // NewTasksQueue creates a new TaskQueue with the provided options |
| 180 | func 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 | |
| 210 | func (q *TaskQueue) getCompactionGroup() *compactionGroup { |
| 211 | return compactionGroupPool.Get().(*compactionGroup) |