controller

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2015 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package controller provides reusable support for controller implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue interface {
	Pop() interface{}
	AddIfNotPresent(interface{}) error
}

Queue is a narrow abstraction of a cache.FIFO.

type QueueRetryManager

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

QueueRetryManager retries a resource by re-queueing it into a Queue up to MaxRetries number of times.

func NewQueueRetryManager

func NewQueueRetryManager(queue Queue, keyFunc kcache.KeyFunc, maxRetries int) *QueueRetryManager

NewQueueRetryManager safely creates a new QueueRetryManager.

func (*QueueRetryManager) Forget

func (r *QueueRetryManager) Forget(resource interface{})

Forget resets the retry count for resource.

func (*QueueRetryManager) Retry

func (r *QueueRetryManager) Retry(resource interface{})

Retry will enqueue resource until maxRetries for that resource has been exceeded, at which point resource will be forgotten and no longer retried.

A maxRetries value of -1 is interpreted as retry forever.

type RetryController

type RetryController struct {
	// Queue is where work is retrieved for Handle.
	Queue Queue

	// Handle is expected to process the next resource from the queue.
	Handle func(interface{}) error

	// ShouldRetry returns true if the resource and error returned from
	// HandleNext should trigger a retry via the RetryManager.
	ShouldRetry func(interface{}, error) bool

	// RetryManager is fed the handled resource if Handle returns a Retryable
	// error. If Handle returns no error, the RetryManager is asked to forget
	// the resource.
	RetryManager RetryManager
}

RetryController is a RunnableController which delegates resource handling to a function and knows how to safely manage retries of a resource which failed to be successfully handled.

func (*RetryController) Run

func (c *RetryController) Run()

Run begins processing resources from Queue asynchronously.

type RetryManager

type RetryManager interface {
	// Retry will cause resource processing to be retried (for example, by
	// requeueing resource)
	Retry(resource interface{})

	// Forget will cause the manager to erase all prior knowledge of resource
	// and reclaim internal resources associated with state tracking of
	// resource.
	Forget(resource interface{})
}

RetryManager knows how to retry processing of a resource, and how to forget a resource it may be tracking the state of.

type RunnableController

type RunnableController interface {
	// Run starts the asynchronous controller loop.
	Run()
}

RunnableController is a controller which implements a Run loop.

Jump to

Keyboard shortcuts

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