api

package
v0.95.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 17, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package api provides utilities to make API calls against the Databricks API.

This package draws inspiration from the AWS and GCP SDKs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(ctx context.Context, call Call, opts ...Option) error

Execute makes a call to a Databricks API using the given options.

Types

type BackoffPolicy

type BackoffPolicy struct {
	// Initial delay to be used for the first retry; defaults to 1 second.
	Initial time.Duration

	// Maximum value for the retry delay; defaults to 60 seconds.
	Maximum time.Duration

	// Factor by which the delay is multiplied after each retry. The value
	// must be greater or equal to 1. If not, it defaults to 2.
	Factor float64
	// contains filtered or unexported fields
}

BackoffPolicy implements an exponential backoff policy. The delay betwen retries is randomly computed between 0 and the "exponential delay" as recommended in Exponential Backoff And Jitter. The retry delay start from Initial and grows exponentially by Factor at every retry. The maximum retry delay is capped by Maximum.

There is no parameter to limit the number of retries. This is intended as such logic should be implemented upstream (e.g. in a Retrier).

Important: BackoffPolicies cannot conveniently be reset. This is intentional and client should rather create a new BackoffPolicy instead of resetting an existing one.

func (*BackoffPolicy) Delay

func (bp *BackoffPolicy) Delay() time.Duration

type Call

type Call func(context.Context) error

Call represents a call to a Databricks API.

type Limiter

type Limiter interface {
	Wait(context.Context) error
}

Limiter is anything that can wait. It is typically used to implement client-side rate limiting. Implementation of this interface must be thread-safe.

type Option

type Option interface {
	Apply(*Options) error
}

Option is an option used by Execute to control the behavior of an API call. An Option essentially act as a convenient way to configure Options.

func WithLimiter

func WithLimiter(l Limiter) Option

WithLimiter configures to use the given Limiter provider.

The limiter is used to potential rate limit the API call. If no limiter is provided, the API call is not rate limited.

func WithRetrier

func WithRetrier(provider func() Retrier) Option

WithRetrier configures to use the given Retrier provider. If no retrier is provided, the API call is not retried.

The provider function must be thread-safe.

func WithTimeout

func WithTimeout(t time.Duration) Option

WithTimeout is a convenience option to set the timeout duration in the Call context. If the context already has a deadline, that deadline is updated to the minimum of the context's deadline and the timeout.

The timeout covers the whole Call execution; it is not a timeout of each intermediary API call.

type Options

type Options struct {
	// contains filtered or unexported fields
}

Options to control the behavior of an API call.

type Retrier

type Retrier interface {
	// IsRetriable returns whether an error is retriable and how long the
	// caller should wait before retrying. Implementation should assume that
	// the given error is never nil.
	IsRetriable(err error) (time.Duration, bool)
}

Retrier defines a retry behavior.

func RetryOn

func RetryOn(bp BackoffPolicy, isRetriable func(error) bool) Retrier

RetryOn returns a Retrier that retries based on the isRetriable predicate and relies on the given backoff policy to decide how long to wait between retries.

Important: the retrier has its own copy of the backoff policy which cannot be trivially reset by design. Users who need to reset the backoff policy should rather create a new retrier.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL