stock_inventory

package
v1.331.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LeaderWorker

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

LeaderWorker wraps Worker with Kubernetes leader election so that only one replica runs the inventory loop at a time.

func NewLeaderWorker

func NewLeaderWorker(
	repo StockRepository,
	k8sClient kubernetes.Interface,
	workerConfig WorkerConfig,
	electionConfig schedule.LeaderElectionConfig,
) *LeaderWorker

NewLeaderWorker creates a LeaderWorker using the provided Kubernetes client and leader election configuration.

func (*LeaderWorker) Run

func (lw *LeaderWorker) Run(ctx context.Context)

Run starts the leader election loop. This blocks until ctx is cancelled.

func (*LeaderWorker) Stop

func (lw *LeaderWorker) Stop()

Stop stops the leader worker.

type StockRepository

type StockRepository interface {
	CreateStockSession(ctx context.Context) error
	CountStockSessions(ctx context.Context) (int, error)
	// PurgeStockSessions deletes all pre-warmed stock sessions. Called on
	// worker startup so that stale sessions (e.g. built from an old image)
	// are replaced with fresh ones.
	PurgeStockSessions(ctx context.Context) error
}

StockRepository manages the creation and counting of stock sessions.

type Worker

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

Worker periodically checks the number of available stock sessions and creates new ones when the count falls below TargetCount.

func NewWorker

func NewWorker(repo StockRepository, config WorkerConfig) *Worker

NewWorker creates a new stock inventory worker.

func (*Worker) Start

func (w *Worker) Start(ctx context.Context) error

Start begins the worker loop in a background goroutine.

func (*Worker) Stop

func (w *Worker) Stop()

Stop gracefully stops the worker.

type WorkerConfig

type WorkerConfig struct {
	// CheckInterval is how often to check and replenish stock sessions.
	CheckInterval time.Duration
	// TargetCount is the desired number of available stock sessions.
	TargetCount int
	// Enabled indicates whether the worker should run.
	Enabled bool
}

WorkerConfig contains configuration for the stock inventory worker.

func DefaultWorkerConfig

func DefaultWorkerConfig() WorkerConfig

DefaultWorkerConfig returns the default worker configuration.

Jump to

Keyboard shortcuts

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