Documentation
¶
Overview ¶
Package shutdown provides functionality for graceful application shutdown.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GracefulShutdown ¶
func GracefulShutdown(ctx context.Context, logger *logging.ContextLogger, shutdownFunc func() error) error
GracefulShutdown waits for termination signals and calls the provided shutdown function. It handles OS signals (SIGINT, SIGTERM, SIGHUP) and context cancellation to trigger graceful shutdown. It also handles multiple signals, forcing exit if a second signal is received during shutdown. A default timeout of 30 seconds is applied to the shutdown function to prevent hanging.
Parameters:
- ctx: Context that can be cancelled to trigger shutdown
- logger: Logger for recording shutdown events
- shutdownFunc: Function to execute during shutdown
Returns:
- The error from the shutdown function, if any
func SetupGracefulShutdown ¶
func SetupGracefulShutdown(ctx context.Context, logger *logging.ContextLogger, shutdownFunc func() error) (context.CancelFunc, <-chan error)
SetupGracefulShutdown sets up a goroutine that will handle graceful shutdown. It creates a new context with cancellation and starts a background goroutine that calls GracefulShutdown. This allows for both signal-based and programmatic shutdown initiation.
Parameters:
- ctx: Parent context for the shutdown context
- logger: Logger for recording shutdown events
- shutdownFunc: Function to execute during shutdown
Returns:
- A cancel function that can be called to trigger shutdown programmatically
- A channel that will receive any error that occurs during shutdown
Types ¶
This section is empty.