Documentation
¶
Overview ¶
Package shutdown provides graceful shutdown coordination for control-plane components. It handles SIGTERM/SIGINT signals, stops accepting new requests, waits for in-flight operations to complete, and closes resources cleanly.
**Validates: Requirements 15.1, 15.2, 15.3, 15.4, 15.5**
Index ¶
Constants ¶
const DefaultTimeout = 30 * time.Second
DefaultTimeout is the default graceful shutdown timeout.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CloserComponent ¶
type CloserComponent struct {
// contains filtered or unexported fields
}
CloserComponent wraps an io.Closer for graceful shutdown.
**Validates: Requirements 15.4**
func NewCloserComponent ¶
func NewCloserComponent(name string, closer io.Closer) *CloserComponent
NewCloserComponent creates a new closer shutdown component.
func (*CloserComponent) Name ¶
func (c *CloserComponent) Name() string
Name returns the component name.
type Component ¶
type Component interface {
// Name returns the component name for logging.
Name() string
// Shutdown gracefully shuts down the component.
// It should return within the given context deadline.
Shutdown(ctx context.Context) error
}
Component represents a component that can be gracefully shut down.
type Coordinator ¶
type Coordinator struct {
// contains filtered or unexported fields
}
Coordinator manages graceful shutdown of multiple components. It handles SIGTERM/SIGINT signals and coordinates shutdown of registered components.
**Validates: Requirements 15.1, 15.2, 15.3, 15.4, 15.5**
func NewCoordinator ¶
func NewCoordinator(opts ...Option) *Coordinator
NewCoordinator creates a new shutdown coordinator.
func (*Coordinator) ExitCode ¶
func (c *Coordinator) ExitCode() int
ExitCode returns the exit code after shutdown. Returns 0 for clean shutdown, 1 for forced termination.
**Validates: Requirements 15.5**
func (*Coordinator) Register ¶
func (c *Coordinator) Register(component Component)
Register adds a component to be shut down during graceful shutdown. Components are shut down in reverse order of registration (LIFO).
func (*Coordinator) Shutdown ¶
func (c *Coordinator) Shutdown()
Shutdown initiates graceful shutdown of all registered components. It stops accepting new requests, waits for in-flight operations to complete (up to the configured timeout), and closes resources cleanly.
**Validates: Requirements 15.1, 15.2, 15.3, 15.4, 15.5**
func (*Coordinator) WaitForSignal ¶
func (c *Coordinator) WaitForSignal()
WaitForSignal blocks until a SIGTERM or SIGINT signal is received, then initiates graceful shutdown.
**Validates: Requirements 15.1**
type FuncComponent ¶
type FuncComponent struct {
// contains filtered or unexported fields
}
FuncComponent wraps a shutdown function as a component.
func NewFuncComponent ¶
func NewFuncComponent(name string, fn func(ctx context.Context) error) *FuncComponent
NewFuncComponent creates a new function-based shutdown component.
type GRPCServerComponent ¶
type GRPCServerComponent struct {
// contains filtered or unexported fields
}
GRPCServerComponent wraps a gRPC server for graceful shutdown.
func NewGRPCServerComponent ¶
func NewGRPCServerComponent(name string, server GRPCServerShutdowner) *GRPCServerComponent
NewGRPCServerComponent creates a new gRPC server shutdown component.
func (*GRPCServerComponent) Name ¶
func (c *GRPCServerComponent) Name() string
Name returns the component name.
type GRPCServerShutdowner ¶
type GRPCServerShutdowner interface {
GracefulStop()
}
GRPCServerShutdowner is the interface for gRPC servers that can be gracefully stopped.
type HTTPServerComponent ¶
type HTTPServerComponent struct {
// contains filtered or unexported fields
}
HTTPServerComponent wraps an http.Server for graceful shutdown.
**Validates: Requirements 15.1, 15.2, 15.3**
func NewHTTPServerComponent ¶
func NewHTTPServerComponent(name string, server *http.Server) *HTTPServerComponent
NewHTTPServerComponent creates a new HTTP server shutdown component.
func (*HTTPServerComponent) Name ¶
func (c *HTTPServerComponent) Name() string
Name returns the component name.
type Option ¶
type Option func(*Coordinator)
Option configures a Coordinator.
func WithSignalChannel ¶
WithSignalChannel sets a custom signal channel (for testing).
func WithTimeout ¶
WithTimeout sets the shutdown timeout.
type WorkerComponent ¶
type WorkerComponent struct {
// contains filtered or unexported fields
}
WorkerComponent wraps a worker for graceful shutdown.
func NewWorkerComponent ¶
func NewWorkerComponent(name string, worker WorkerShutdowner) *WorkerComponent
NewWorkerComponent creates a new worker shutdown component.
func (*WorkerComponent) Name ¶
func (c *WorkerComponent) Name() string
Name returns the component name.
type WorkerShutdowner ¶
type WorkerShutdowner interface {
Stop()
}
WorkerShutdowner is the interface for workers that can be stopped.