github.com/uber/kraken@v0.1.4/lib/persistedretry/config.go (about)

     1  // Copyright (c) 2016-2019 Uber Technologies, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  package persistedretry
    15  
    16  import "time"
    17  
    18  // Config defines Manager configuration.
    19  type Config struct {
    20  	IncomingBuffer int `yaml:"incoming_buffer"`
    21  	RetryBuffer    int `yaml:"retry_buffer"`
    22  
    23  	NumIncomingWorkers int `yaml:"num_incoming_workers"`
    24  	NumRetryWorkers    int `yaml:"num_retry_workers"`
    25  
    26  	// Max rate of task execution across all workers.
    27  	MaxTaskThroughput time.Duration `yaml:"max_task_throughput"`
    28  
    29  	// Interval at which failed tasks should be retried.
    30  	RetryInterval time.Duration `yaml:"retry_interval"`
    31  
    32  	// Interval at which retries should be polled from storage.
    33  	PollRetriesInterval time.Duration `yaml:"poll_retries_interval"`
    34  
    35  	// Flags that zero-value channel sizes should not have defaults applied.
    36  	Testing bool
    37  }
    38  
    39  func (c Config) applyDefaults() Config {
    40  	if c.NumIncomingWorkers == 0 {
    41  		c.NumIncomingWorkers = 4
    42  	}
    43  	if c.NumRetryWorkers == 0 {
    44  		c.NumRetryWorkers = 2
    45  	}
    46  	if c.MaxTaskThroughput == 0 {
    47  		c.MaxTaskThroughput = 10 * time.Millisecond
    48  	}
    49  	if c.PollRetriesInterval == 0 {
    50  		c.PollRetriesInterval = 15 * time.Second
    51  	}
    52  	if c.RetryInterval == 0 {
    53  		c.RetryInterval = 30 * time.Second
    54  	}
    55  	if !c.Testing {
    56  		if c.IncomingBuffer == 0 {
    57  			c.IncomingBuffer = 1000
    58  		}
    59  		if c.RetryBuffer == 0 {
    60  			c.RetryBuffer = 1000
    61  		}
    62  	}
    63  	return c
    64  }