pollers

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusSucceeded  = "Succeeded"
	StatusCanceled   = "Canceled"
	StatusFailed     = "Failed"
	StatusInProgress = "InProgress"
)

Variables

This section is empty.

Functions

func DecodeID

func DecodeID(tk string) (string, string, error)

DecodeID decodes the poller ID, returning [pollerID, kind] or an error.

func Failed

func Failed(s string) bool

Failed returns true if the LRO's state is terminal failure.

func IsTerminalState

func IsTerminalState(s string) bool

IsTerminalState returns true if the LRO's state is terminal.

func IsValidURL

func IsValidURL(s string) bool

IsValidURL verifies that the URL is valid and absolute.

func KindFromToken

func KindFromToken(pollerID, token string) (string, error)

KindFromToken extracts the poller kind from the provided token. If the pollerID doesn't match what's in the token an error is returned.

func MakeID

func MakeID(pollerID string, kind string) string

MakeID returns the poller ID from the provided values.

func PollerType

func PollerType(p *Poller) reflect.Type

PollerType returns the concrete type of the poller (FOR TESTING PURPOSES).

func StatusCodeValid

func StatusCodeValid(resp *http.Response) bool

returns true if the LRO response contains a valid HTTP status code

Types

type NopPoller

type NopPoller struct{}

used if the operation synchronously completed

func (*NopPoller) Done

func (*NopPoller) Done() bool

func (*NopPoller) FinalGetURL

func (*NopPoller) FinalGetURL() string

func (*NopPoller) Status

func (*NopPoller) Status() string

func (*NopPoller) URL

func (*NopPoller) URL() string

func (*NopPoller) Update

func (*NopPoller) Update(*http.Response) error

type Operation

type Operation interface {
	Done() bool
	Update(resp *http.Response) error
	FinalGetURL() string
	URL() string
	Status() string
}

Operation abstracts the differences between concrete poller types.

type Poller

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

Poller encapsulates state and logic for polling on long-running operations.

func NewPoller

func NewPoller(lro Operation, resp *http.Response, pl pipeline.Pipeline) *Poller

NewPoller creates a Poller from the specified input.

func (*Poller) Done

func (l *Poller) Done() bool

Done returns true if the LRO has reached a terminal state.

func (*Poller) FinalResponse

func (l *Poller) FinalResponse(ctx context.Context, respType interface{}) (*http.Response, error)

FinalResponse will perform a final GET request and return the final HTTP response for the polling operation and unmarshall the content of the payload into the respType interface that is provided.

func (*Poller) Poll

func (l *Poller) Poll(ctx context.Context) (*http.Response, error)

Poll sends a polling request to the polling endpoint and returns the response or error.

func (*Poller) PollUntilDone

func (l *Poller) PollUntilDone(ctx context.Context, freq time.Duration, respType interface{}) (*http.Response, error)

PollUntilDone will handle the entire span of the polling operation until a terminal state is reached, then return the final HTTP response for the polling operation and unmarshal the content of the payload into the respType interface that is provided. freq - the time to wait between intervals in absence of a Retry-After header. Minimum is one second.

func (*Poller) ResumeToken

func (l *Poller) ResumeToken() (string, error)

ResumeToken returns a token string that can be used to resume a poller that has not yet reached a terminal state.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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