state

package
v0.0.0-...-bd1a880 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package state provides utilities for container state management

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidStateTransition = errors.New("invalid container state transition")

ErrInvalidStateTransition is returned when a state transition is invalid

ValidStateTransitions defines the valid state transitions for containers

ValidStates is a list of all valid container states

Functions

This section is empty.

Types

type ContainerInfo

type ContainerInfo struct {
	ID            string
	Name          string
	CurrentState  ContainerState
	PreviousState ContainerState
	ExitCode      int
	LastUpdated   time.Time
	StartedAt     time.Time
	FinishedAt    time.Time
	Error         string
	RestartCount  int
	HealthStatus  string
}

ContainerInfo holds information about a container

type ContainerState

type ContainerState string

ContainerState represents the possible states of a container

const (
	// StateCreated represents a created container
	StateCreated ContainerState = "created"
	// StateRunning represents a running container
	StateRunning ContainerState = "running"
	// StatePaused represents a paused container
	StatePaused ContainerState = "paused"
	// StateRestarting represents a restarting container
	StateRestarting ContainerState = "restarting"
	// StateRemoving represents a container being removed
	StateRemoving ContainerState = "removing"
	// StateExited represents an exited container
	StateExited ContainerState = "exited"
	// StateDead represents a dead container
	StateDead ContainerState = "dead"
	// StateUnknown represents an unknown container state
	StateUnknown ContainerState = "unknown"
)

type Manager

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

Manager manages container state tracking and transitions

func NewManager

func NewManager(client client.APIClient, logger *logrus.Logger) *Manager

NewManager creates a new container state manager

func (*Manager) GetContainerInfo

func (m *Manager) GetContainerInfo(containerID string) (*ContainerInfo, error)

GetContainerInfo gets information about a container

func (*Manager) GetState

func (m *Manager) GetState(containerID string) (ContainerState, error)

GetState gets the current state of a container

func (*Manager) IsValidTransition

func (m *Manager) IsValidTransition(fromState, toState ContainerState) bool

IsValidTransition checks if a state transition is valid

func (*Manager) ListContainers

func (m *Manager) ListContainers() map[string]ContainerState

ListContainers lists all tracked containers and their states

func (*Manager) RegisterStateChangeHandler

func (m *Manager) RegisterStateChangeHandler(state ContainerState, handler StateChangeHandler)

RegisterStateChangeHandler registers a callback for a specific state transition

func (*Manager) StartWatching

func (m *Manager) StartWatching() error

StartWatching starts watching for container state changes

func (*Manager) StopWatching

func (m *Manager) StopWatching()

StopWatching stops watching for container state changes

func (*Manager) UpdateState

func (m *Manager) UpdateState(containerID string, state ContainerState) error

UpdateState updates the state of a container

type StateChangeHandler

type StateChangeHandler func(containerID string, oldState, newState ContainerState, info *ContainerInfo)

StateChangeHandler is a callback for state changes

Jump to

Keyboard shortcuts

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