Documentation
¶
Index ¶
- func CanTransition(from, to State) bool
- type Event
- type Info
- type Machine
- func (m *Machine) GetCurrentState() State
- func (m *Machine) GetLastError() error
- func (m *Machine) GetRetryCount(state State) int
- func (m *Machine) GetRetryDelay(state State) time.Duration
- func (m *Machine) SendEvent(event Event)
- func (m *Machine) SetError(err error)
- func (m *Machine) ShouldRetry(state State) bool
- func (m *Machine) Shutdown()
- func (m *Machine) Start()
- func (m *Machine) Subscribe() <-chan Transition
- type State
- type Transition
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanTransition ¶
CanTransition checks if a transition from one state to another is valid
Types ¶
type Event ¶
type Event string
Event represents events that can trigger state transitions
const ( // EventStart triggers initial startup EventStart Event = "start" // EventCoreStarted indicates core subprocess started successfully EventCoreStarted Event = "core_started" // EventCoreReady indicates core is ready to serve requests EventCoreReady Event = "core_ready" // EventAPIConnected indicates successful API/SSE connection EventAPIConnected Event = "api_connected" // EventConnectionLost indicates lost connection to core EventConnectionLost Event = "connection_lost" // EventCoreExited indicates core subprocess exited EventCoreExited Event = "core_exited" // EventPortConflict indicates core failed due to port conflict EventPortConflict Event = "port_conflict" // EventDBLocked indicates core failed due to database lock EventDBLocked Event = "db_locked" // EventConfigError indicates core failed due to configuration error EventConfigError Event = "config_error" // EventPermissionError indicates core failed due to permission error EventPermissionError Event = "permission_error" EventDockerUnavailable Event = "docker_unavailable" // EventDockerRecovered indicates Docker engine became available again EventDockerRecovered Event = "docker_recovered" // EventGeneralError indicates core failed with general error EventGeneralError Event = "general_error" // EventRetry triggers retry attempt EventRetry Event = "retry" // EventShutdown triggers shutdown EventShutdown Event = "shutdown" // EventTimeout indicates a timeout occurred EventTimeout Event = "timeout" // EventSkipCore indicates core launch should be skipped EventSkipCore Event = "skip_core" )
type Info ¶
type Info struct {
Name State
Description string
IsError bool
CanRetry bool
UserMessage string
Timeout *time.Duration
}
Info provides metadata about each state
type Machine ¶
type Machine struct {
// contains filtered or unexported fields
}
Machine manages state transitions for the tray application
func NewMachine ¶
func NewMachine(logger *zap.SugaredLogger) *Machine
NewMachine creates a new state machine
func (*Machine) GetCurrentState ¶
GetCurrentState returns the current state
func (*Machine) GetLastError ¶
GetLastError returns the last error that occurred
func (*Machine) GetRetryCount ¶
GetRetryCount returns the current retry count for the given state
func (*Machine) GetRetryDelay ¶
GetRetryDelay returns the retry delay for the given state
func (*Machine) ShouldRetry ¶
ShouldRetry checks if we should retry for the given state (exported for error handlers)
func (*Machine) Shutdown ¶
func (m *Machine) Shutdown()
Shutdown gracefully shuts down the state machine
func (*Machine) Subscribe ¶
func (m *Machine) Subscribe() <-chan Transition
Subscribe returns a channel for receiving state transitions
type State ¶
type State string
State represents the current state of the tray application
const ( // StateInitializing represents the initial startup state StateInitializing State = "initializing" // StateLaunchingCore represents launching the core subprocess StateLaunchingCore State = "launching_core" // StateWaitingForCore represents waiting for core to become ready StateWaitingForCore State = "waiting_for_core" // StateConnectingAPI represents establishing API/SSE connection StateConnectingAPI State = "connecting_api" // StateConnected represents fully connected and operational StateConnected State = "connected" // StateReconnecting represents attempting to reconnect after disconnection StateReconnecting State = "reconnecting" // StateCoreErrorPortConflict represents core failed due to port conflict StateCoreErrorPortConflict State = "core_error_port_conflict" // StateCoreErrorDBLocked represents core failed due to database lock StateCoreErrorDBLocked State = "core_error_db_locked" // StateCoreErrorDocker represents core failed due to Docker being unavailable StateCoreErrorDocker State = "core_error_docker" // StateCoreRecoveringDocker represents Docker recovery in progress StateCoreRecoveringDocker State = "core_recovering_docker" // StateCoreErrorConfig represents core failed due to configuration error StateCoreErrorConfig State = "core_error_config" // StateCoreErrorPermission represents core failed due to permission error StateCoreErrorPermission State = "core_error_permission" // StateCoreErrorGeneral represents core failed with general error StateCoreErrorGeneral State = "core_error_general" // StateShuttingDown represents clean shutdown in progress StateShuttingDown State = "shutting_down" // StateFailed represents unrecoverable failure StateFailed State = "failed" )