limiter

package
v2.0.0-...-dac0b9e Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MaxInFlight

type MaxInFlight struct {
	// MaxInFlight sets the upper limit on number of jobs running concurrently
	// in the cluster. Must be at least 1.
	MaxInFlight int
	// contains filtered or unexported fields
}

MaxInFlight is a job handler that wraps another job handler (typically the actual job scheduler) and only creates new jobs if the total number of jobs currently running is below a limit.

func New

func New(logger *zap.Logger, scheduler model.JobHandler, maxInFlight int) *MaxInFlight

New creates a MaxInFlight limiter. maxInFlight must be at least 1.

func (*MaxInFlight) Handle

func (l *MaxInFlight) Handle(ctx context.Context, job model.Job) error

Handle either passes the job onto the next handler immediately, or blocks until there is capacity. It returns model.ErrStaleJob if the job data becomes too stale while waiting for capacity.

func (*MaxInFlight) OnAdd

func (l *MaxInFlight) OnAdd(obj any, inInitialList bool)

OnAdd is called by k8s to inform us a resource is added.

func (*MaxInFlight) OnDelete

func (l *MaxInFlight) OnDelete(obj any)

OnDelete is called by k8s to inform us a resource is deleted.

func (*MaxInFlight) OnUpdate

func (l *MaxInFlight) OnUpdate(prev, curr any)

OnUpdate is called by k8s to inform us a resource is updated.

func (*MaxInFlight) RegisterInformer

func (l *MaxInFlight) RegisterInformer(ctx context.Context, factory informers.SharedInformerFactory) error

RegisterInformer registers the limiter to listen for Kubernetes job events, and waits for cache sync.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳