features

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const BatchSize int = 10000

BatchSize is the default number of document to pull in a single request.

View Source
const LongpollTimeout time.Duration = minClientTimeout - 3*time.Second

LongpollTimeout is set to give the changes request a chance to be answered before the client timeout it is set to 3 seconds less.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangesFollower

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

ChangesFollower is a helper for using the changes feed.

There are two modes of operation:

StartOneOff() to fetch the changes from the supplied since sequence
until there are no further pending changes.
Start() to fetch the changes from the supplied since sequence
and then continuing to listen indefinitely for further new changes.

The starting sequence ID can be changed for either mode by using "Since". By default when using:

StartOneOff() the feed will start from the beginning.
Start() the feed will start from "now".

In either mode the response stream can be terminated early by calling Stop(). By default ChangesFollower will suppress transient errors indefinitely and endeavour to run to completion or listen forever. For applications where that behaviour is not desirable an alternate option is available where a duration may be specified to limit the time since the last successful response that transient errors will be suppressed. It should be noted that some errors considered terminal, for example, the database not existing or invalid credentials are never suppressed and will return an Error immediately. The named attributes for "PostChangesOptions" are used to configure the behaviour of the ChangesFollower. However, a subset of the attributes are invalid as they are configured internally by the implementation and will cause an Error to be returned if supplied. These invalid options are:

  • Descending
  • Feed
  • Heartbeat
  • LastEventID
  • Timeout

Only the value of "_selector" is permitted for the PostChangesOptions's "Filter" option. Selector based filters perform better than JS based filters and using one of the alternative JS based filter types will cause ChangesFollower to return an Error. It should also be noted that the "Limit" parameter will truncate the response at the given number of changes in either operating mode. The ChangesFollower requires the Cloudant client to have HTTP timeout of at least 1 minute. The default client configuration has a sufficiently long timeout.

func NewChangesFollower

NewChangesFollower returns a new ChangesFollower or an error if provided configuration is invalid.

func NewChangesFollowerWithContext

func NewChangesFollowerWithContext(ctx context.Context, c *cloudantv1.CloudantV1, o *cloudantv1.PostChangesOptions) (*ChangesFollower, error)

NewChangesFollowerWithContext returns a new ChangesFollower initiated with a given context or an error if provided configuration is invalid.

func (*ChangesFollower) SetErrorTolerance

func (cf *ChangesFollower) SetErrorTolerance(d time.Duration) error

SetErrorTolerance sets the duration to suppress errors, measured from the previous successful request.

func (*ChangesFollower) Start

func (cf *ChangesFollower) Start() (<-chan ChangesItem, error)

Start returns a channel that will stream all available changes and keep listening for new changes until reaching an end condition.

The end conditions are:

  • a terminal error (e.g. unauthorized client).
  • transient errors occur for longer than the error suppression duration.
  • the number of changes received reaches the limit specified in the "PostChangesOptions" args used to instantiate this ChangesFollower.
  • ChangesFollower's Stop() is called.

The same change may be received more than once.

Returns a channel of ChangesItem structs or an error if ChangesFollower's Start() or StartOneOff() was already called or terminal error is recevied from the service during setup.

func (*ChangesFollower) StartOneOff

func (cf *ChangesFollower) StartOneOff() (<-chan ChangesItem, error)

StartOneOff returns a channel that will stream all available changes until there are no further changes pending or reaching an end condition.

The end conditions are:

  • a terminal error (e.g. unauthorized client).
  • transient errors occur for longer than the error suppression duration.
  • the number of changes received reaches the limit specified in the "PostChangesOptions" used to instantiate this ChangesFollower.
  • ChangesFollower's Stop() is called.

The same change may be received more than once.

Returns a channel of ChangesItem structs or an error if ChangesFollower's Start() or StartOneOff() was already called or terminal error is recevied from the service during setup.

func (*ChangesFollower) Stop

func (cf *ChangesFollower) Stop()

Stop this ChangesFollower.

type ChangesItem

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

ChangesItem is a wrapper structure around cloudantv1.ChangesResultItem with addtitional attribute Error for errors received during the run.

func (ChangesItem) Item

Item is a ChangesItem's getter for cloudantv1.ChangesResultItem that either returns an acquired item or an error received during its fetch.

type Mode

type Mode int

Mode are enums for changes follower's operation mode.

const (
	// Finite mode is an alias for StartOneOff()
	Finite Mode = iota
	// Listen mode is an alias for Start()
	Listen
)

type TransientErrorSuppression

type TransientErrorSuppression int

TransientErrorSuppression are enums for changes follower's transient errors suppression mode.

const (
	// Always suppress transient errors
	Always TransientErrorSuppression = iota
	// Never suppress transient errors
	Never
	// Timer specifies a time duration for suppressing transient errors
	Timer
)

Jump to

Keyboard shortcuts

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