default.go raw

   1  package retry
   2  
   3  import "time"
   4  
   5  func defaultNameConfig() nameConfig {
   6  	return nameConfig{}
   7  }
   8  
   9  func defaultRetryConfig() *RetryConfig {
  10  	return &RetryConfig{
  11  		mc: map[nameConfig]*methodConfig{
  12  			// default value for all services and methods
  13  			defaultNameConfig(): defaultMethodConfig(),
  14  		},
  15  		// Temporary is stricter, so it's the default value
  16  		retryThrottling: defaultRetryThrottling(ThrottlingModeTemporary),
  17  	}
  18  }
  19  
  20  func defaultMethodConfig() *methodConfig {
  21  	return &methodConfig{
  22  		NameConfig: []nameConfig{{}},
  23  		RetryPolicy: retryPolicy{
  24  			MaxAttempts:          4,
  25  			InitialBackoff:       Duration(time.Millisecond * 100),
  26  			MaxBackoff:           Duration(time.Second * 20),
  27  			BackoffMultiplier:    2,
  28  			RetryableStatusCodes: []string{"UNAVAILABLE"},
  29  		},
  30  		WaitForReady: true,
  31  	}
  32  }
  33  
  34  func defaultRetryThrottling(mode ThrottlingMode) *retryThrottling {
  35  	if mode == ThrottlingModePersistent {
  36  		return &retryThrottling{
  37  			MaxTokens:  100,
  38  			TokenRatio: 0.1,
  39  		}
  40  	}
  41  
  42  	return &retryThrottling{
  43  		MaxTokens:  6,
  44  		TokenRatio: 0.1,
  45  	}
  46  }
  47