options.go 1.1 KB

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