skipper: Index | Files

package scheduler

import ""

Package scheduler provides a registry to be used as a postprocessor for the routes that use a LIFO filter.


Package Files



const (
    // Key used during routing to pass lifo values from the filters to the proxy.
    LIFOKey = "lifo"

type Config Uses

type Config struct {

    // MaxConcurrency defines how many jobs are allowed to run concurrently.
    // Defaults to 1.
    MaxConcurrency int

    // MaxStackSize defines how many jobs may be waiting in the stack.
    // Defaults to infinite.
    MaxQueueSize int

    // Timeout defines how long a job can be waiting in the stack.
    // Defaults to infinite.
    Timeout time.Duration

    // CloseTimeout sets a maximum duration for how long the queue can wait
    // for the active and queued jobs to finish. Defaults to infinite.
    CloseTimeout time.Duration

Config can be used to provide configuration of the registry.

type GroupedLIFOFilter Uses

type GroupedLIFOFilter interface {

    // Group returns the name of the group.
    Group() string

    // HasConfig indicates that the current filter provides the queue
    // queue settings for the group.
    HasConfig() bool

GroupedLIFOFilter is an extension of the LIFOFilter interface for filters that use a shared queue.

type LIFOFilter Uses

type LIFOFilter interface {

    // SetQueue will be used by the registry to pass in the right queue to
    // the filter.

    // GetQueue is currently used only by tests.
    GetQueue() *Queue

    // Config will be called by the registry once during processing the
    // routing to get the right queue settings from the filter.
    Config() Config

LIFOFilter is the interface that needs to be implemented by the filters that use a LIFO queue maintained by the registry.

type Options Uses

type Options struct {

    // MetricsUpdateTimeout defines the frequence of how often the LIFO metrics
    // are updated when they are enabled. Defaults to 1s.
    MetricsUpdateTimeout time.Duration

    // EnableRouteLIFOMetrics enables collecting metrics about the LIFO queues.
    EnableRouteLIFOMetrics bool

    // Metrics must be provided to the registry in order to collect the LIFO metrics.
    Metrics metrics.Metrics

Options provides options for the registry.

type Queue Uses

type Queue struct {
    // contains filtered or unexported fields

Queue objects implement a LIFO queue for handling requests, with a maximum allowed concurrency and queue size. Currently, they can be used from the lifo and lifoGroup filters in the filters/scheduler package only.

func (*Queue) Config Uses

func (q *Queue) Config() Config

Config returns the configuration that the queue was created with.

func (*Queue) Status Uses

func (q *Queue) Status() QueueStatus

Status returns the current status of a queue.

func (*Queue) Wait Uses

func (q *Queue) Wait() (done func(), err error)

Wait blocks until a request can be processed or needs to be rejected. When it can be processed, calling done indicates that it has finished. It is mandatory to call done() the request was processed. When the request needs to be rejected, an error will be returned.

type QueueStatus Uses

type QueueStatus struct {

    // ActiveRequests represents the number of the requests currently being handled.
    ActiveRequests int

    // QueuedRequests represents the number of requests waiting to be handled.
    QueuedRequests int

    // Closed indicates that the queue was closed.
    Closed bool

QueueStatus reports the current status of a queue. It can be used for metrics.

type Registry Uses

type Registry struct {
    // contains filtered or unexported fields

Registry maintains a set of LIFO queues. It is used to preserve LIFO queue instances across multiple generations of the routing. It implements the routing.PostProcessor interface, it is enough to just pass in to routing.Routing when initializing it.

When the EnableRouteLIFOMetrics is set, then the registry starts a background goroutine for regularly take snapshots of the active lifo queues and update the corresponding metrics. This goroutine is started when the first lifo filter is detected and returns when the registry is closed. Individual metrics objects (keys) are used for each lifo filter, and one for each lifo group defined by the lifoGroup filter.

func NewRegistry Uses

func NewRegistry() *Registry

NewRegistry creates a registry with the default options.

func RegistryWith Uses

func RegistryWith(o Options) *Registry

RegistryWith (Options) creates a registry with the provided options.

func (*Registry) Close Uses

func (r *Registry) Close()

Close closes the registry, including gracefull tearing down the stored queues.

func (*Registry) Do Uses

func (r *Registry) Do(routes []*routing.Route) []*routing.Route

Do implements routing.PostProcessor and sets the queue for the scheduler filters.

It preserves the existing queue when available.

Package scheduler imports 7 packages (graph) and is imported by 6 packages. Updated 2020-03-11. Refresh now. Tools for package owners.