Documentation
¶
Overview ¶
Package backend 监督受管 Python 后端的生命周期。
Index ¶
- Variables
- type ControlMailbox
- func (m *ControlMailbox) BeforeShutdown(commandID string)
- func (m *ControlMailbox) Close()
- func (m *ControlMailbox) InfrastructureError() error
- func (m *ControlMailbox) Receive(ctx context.Context) (protocol.ControlCommand, error)
- func (m *ControlMailbox) SetBeforeShutdown(callback func(string))
- func (m *ControlMailbox) SetReaderError(err error)
- func (m *ControlMailbox) SetStage(stage protocol.Stage)
- func (m *ControlMailbox) SetStageCallback(callback func(protocol.Stage))
- func (m *ControlMailbox) StopAccepting()
- func (m *ControlMailbox) Submit(ctx context.Context, command protocol.ControlCommand) error
- func (m *ControlMailbox) TerminalCommand() (protocol.ControlCommand, bool)
- type ControlReceiver
- type Dependencies
- type EntryChecker
- type Error
- type EventEmitter
- type HTTPCloser
- type HealthChecker
- type Lease
- type LockSet
- type Logger
- type LoggerFactory
- type ManagedProcess
- type ManagedSupervisor
- type Mode
- type PIDProbe
- type RepositoryChecker
- type RepositoryResult
- type Request
- type StateStore
- type Timer
- type Transaction
- type TransactionHandle
- type TransactionInput
- type UVRunner
Constants ¶
This section is empty.
Variables ¶
var ( // ErrControlStopped 表示控制 reader 已停止接受新命令。 ErrControlStopped = errors.New("backend control mailbox is stopped") // ErrControlMailboxClosed 表示控制 mailbox 已永久收口。 ErrControlMailboxClosed = errors.New("backend control mailbox is closed") )
var ( ErrEntryNotFound = errors.New("backend entry file not found") ErrEntryUnsafe = errors.New("backend entry file identity is unsafe") )
EntryError 分类受管入口文件的稳定失败原因。
var ErrTransactionNotFound = errTransactionNotFound{}
ErrTransactionNotFound 表示当前没有 backend 事务。
Functions ¶
This section is empty.
Types ¶
type ControlMailbox ¶
type ControlMailbox struct {
// contains filtered or unexported fields
}
ControlMailbox 是 ControlReader 与 Supervisor loop 之间的有界 FIFO。 Submit 不执行进程或网络副作用;终止命令在入队时记录 first-wins latch。
func NewControlMailbox ¶
func NewControlMailbox(capacity int) *ControlMailbox
NewControlMailbox 创建有界控制 FIFO;非正容量使用稳定默认值。
func (*ControlMailbox) BeforeShutdown ¶
func (m *ControlMailbox) BeforeShutdown(commandID string)
BeforeShutdown 返回当前 shutdown gate 回调。
func (*ControlMailbox) Close ¶
func (m *ControlMailbox) Close()
Close 终止 mailbox;已入队命令仍可被 Receive 消费一次。
func (*ControlMailbox) InfrastructureError ¶
func (m *ControlMailbox) InfrastructureError() error
InfrastructureError 返回尚未被 Receive 消费的 reader 故障。
func (*ControlMailbox) Receive ¶
func (m *ControlMailbox) Receive(ctx context.Context) (protocol.ControlCommand, error)
Receive 按 FIFO 取出一个命令,并响应 ctx 取消。
func (*ControlMailbox) SetBeforeShutdown ¶
func (m *ControlMailbox) SetBeforeShutdown(callback func(string))
SetBeforeShutdown 注册 shutdown 被消费前的 reader 停止回调。
func (*ControlMailbox) SetReaderError ¶
func (m *ControlMailbox) SetReaderError(err error)
SetReaderError 将控制 reader 的基础设施故障交给 Supervisor 消费, 使其先收口受管进程再由 CLI 分类最终错误。
func (*ControlMailbox) SetStage ¶
func (m *ControlMailbox) SetStage(stage protocol.Stage)
SetStage 将 backend stage 转发给控制 warning 的消费侧。
func (*ControlMailbox) SetStageCallback ¶
func (m *ControlMailbox) SetStageCallback(callback func(protocol.Stage))
SetStageCallback 注册当前 backend stage 的只读同步回调。
func (*ControlMailbox) StopAccepting ¶
func (m *ControlMailbox) StopAccepting()
StopAccepting 先唤醒背压中的 producer,再阻止后续命令进入 FIFO。
func (*ControlMailbox) Submit ¶
func (m *ControlMailbox) Submit(ctx context.Context, command protocol.ControlCommand) error
Submit 将已校验命令入队;满队列时通过 ctx 背压而非丢弃命令。
func (*ControlMailbox) TerminalCommand ¶
func (m *ControlMailbox) TerminalCommand() (protocol.ControlCommand, bool)
TerminalCommand 返回入队时记录的 first-wins 终止命令。
type ControlReceiver ¶
type ControlReceiver interface {
Receive(context.Context) (protocol.ControlCommand, error)
}
ControlReceiver 为监督循环提供已由 ControlReader 校验并按 FIFO 排队的命令。
type Dependencies ¶
type Dependencies struct {
Lock LockSet
State StateStore
Repository RepositoryChecker
Entry EntryChecker
UV UVRunner
Health HealthChecker
Logger LoggerFactory
Clock func() time.Time
UVPath string
PythonPath string
PythonPaths []string
PID PIDProbe
HTTP HTTPCloser
ShutdownTimeout time.Duration
RestartDelay time.Duration
Timer func(time.Duration) <-chan time.Time
NewTimer func(time.Duration) Timer
}
Dependencies 是 ManagedSupervisor 的消费侧依赖集合。
type EntryChecker ¶
EntryChecker 验证受管 backend 入口文件的普通文件与 reparse 身份。
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error 是 backend 向 CLI 暴露的稳定错误,保留错误码、stage、details 与根因。
func (*Error) TerminalStatus ¶
TerminalStatus 返回 backend 失败对应的生命周期终态。
type EventEmitter ¶
type EventEmitter interface {
EmitState(protocol.StateEvent) error
EmitLog(protocol.LogEvent) error
EmitWarning(protocol.WarningEvent) error
}
EventEmitter 是后端监督使用的窄事件出口;顶层 error/result 由 CLI 统一发出。
type HTTPCloser ¶
HTTPCloser 请求受管后端执行优雅关闭。
type HealthChecker ¶
HealthChecker 执行已注入的后端健康与身份检查。
type Logger ¶
type Logger interface {
Record(context.Context, process.StreamRecord) error
LogPath() string
Close() error
}
Logger 记录受管流并提供日志路径与收口操作。
type LoggerFactory ¶
LoggerFactory 延迟创建本次监督操作的日志 sink。
type ManagedProcess ¶
type ManagedProcess interface {
PID() uint32
Exited() <-chan struct{}
Wait(context.Context) (process.ExitResult, error)
Snapshot() ([]process.Info, error)
Terminate(uint32) error
WaitEmpty(context.Context) error
Close() error
}
ManagedProcess 是 backend 需要的进程生命周期能力。
type ManagedSupervisor ¶
type ManagedSupervisor struct {
// contains filtered or unexported fields
}
ManagedSupervisor 监督单个受管后端 Job 的完整生命周期。
func NewManagedSupervisor ¶
func NewManagedSupervisor(layout *config.Layout, deps Dependencies) (*ManagedSupervisor, error)
NewManagedSupervisor 创建可按请求选择 managed 或 development 的后端监督器。
type RepositoryChecker ¶
type RepositoryChecker interface {
Check(context.Context) (RepositoryResult, error)
}
RepositoryChecker 返回经验证的活动仓库 revision。
type RepositoryResult ¶
RepositoryResult 是 backend 需要的仓库检查结果。
type Request ¶
type Request struct {
OperationID string
RuntimePID uint32
Mode Mode
DevelopmentRepo string
Emitter EventEmitter
Control ControlReceiver
BeforeShutdown func(string)
BeforeControlClose func()
}
Request 描述一次受管后端监督请求。
type StateStore ¶
type StateStore interface {
ReadEnvironment(context.Context) (state.EnvironmentState, error)
ReadBackendTransaction(context.Context) (Transaction, error)
BeginBackendTransaction(context.Context, TransactionInput) (TransactionHandle, error)
UpdateBackendTransaction(context.Context, TransactionHandle, protocol.Stage) error
RemoveBackendTransaction(context.Context, TransactionHandle) error
Close() error
}
StateStore 是后端消费的稳定环境与事务存储窄接口。
type Transaction ¶
type Transaction struct {
PID uint32
Version string
Stage protocol.Stage
Handle TransactionHandle
}
Transaction 描述已有 backend 事务的最小事实。
type TransactionHandle ¶
type TransactionHandle interface{}
TransactionHandle 是条件删除 backend 事务所需的不可伪造 token。
type TransactionInput ¶
TransactionInput 描述新建 backend 事务的业务身份。
type UVRunner ¶
type UVRunner interface {
Check(context.Context) error
Executable() string
StartManaged(context.Context, []string, uv.ManagedOptions, process.StreamSink) (ManagedProcess, error)
}
UVRunner 是长驻受管 uv 的唯一启动入口。