github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/retry/retryable_error.go (about)

     1  package retry
     2  
     3  import (
     4  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/backoff"
     5  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
     6  )
     7  
     8  type retryableErrorOption xerrors.RetryableErrorOption
     9  
    10  const (
    11  	TypeNoBackoff   = backoff.TypeNoBackoff
    12  	TypeFastBackoff = backoff.TypeFast
    13  	TypeSlowBackoff = backoff.TypeSlow
    14  )
    15  
    16  // WithBackoff makes retryable error option with custom backoff type
    17  func WithBackoff(t backoff.Type) retryableErrorOption {
    18  	return retryableErrorOption(xerrors.WithBackoff(t))
    19  }
    20  
    21  // WithDeleteSession makes retryable error option with delete session flag
    22  func WithDeleteSession() retryableErrorOption {
    23  	return retryableErrorOption(xerrors.WithDeleteSession())
    24  }
    25  
    26  // RetryableError makes retryable error from options
    27  // RetryableError provides retrying on custom errors
    28  func RetryableError(err error, opts ...retryableErrorOption) error {
    29  	return xerrors.Retryable(
    30  		err,
    31  		func() (retryableErrorOptions []xerrors.RetryableErrorOption) {
    32  			for _, o := range opts {
    33  				if o != nil {
    34  					retryableErrorOptions = append(retryableErrorOptions, xerrors.RetryableErrorOption(o))
    35  				}
    36  			}
    37  
    38  			return retryableErrorOptions
    39  		}()...,
    40  	)
    41  }