options.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package retry
  2. import (
  3. "time"
  4. "github.com/tal-tech/go-zero/core/retry/backoff"
  5. "google.golang.org/grpc/codes"
  6. )
  7. // WithDisable disables the retry behaviour on this call, or this interceptor.
  8. // It's semantically the same to `WithMax(0)`
  9. func WithDisable() *CallOption {
  10. return WithMax(0)
  11. }
  12. // WithMax sets the maximum number of retries on this call, or this interceptor.
  13. func WithMax(maxRetries int) *CallOption {
  14. return &CallOption{apply: func(options *options) {
  15. options.max = maxRetries
  16. }}
  17. }
  18. // WithBackoff sets the `BackoffFunc` used to control time between retries.
  19. func WithBackoff(backoffFunc backoff.Func) *CallOption {
  20. return &CallOption{apply: func(o *options) {
  21. o.backoffFunc = backoffFunc
  22. }}
  23. }
  24. // WithCodes Allow code to be retried.
  25. func WithCodes(retryCodes ...codes.Code) *CallOption {
  26. return &CallOption{apply: func(o *options) {
  27. o.codes = retryCodes
  28. }}
  29. }
  30. // WithPerRetryTimeout timeout for each retry
  31. func WithPerRetryTimeout(timeout time.Duration) *CallOption {
  32. return &CallOption{apply: func(o *options) {
  33. o.perCallTimeout = timeout
  34. }}
  35. }