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.
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.
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.