Documentation ¶
Overview ¶
Package interrupts exposes helpers for graceful handling of interrupt signals
Index ¶
- func Context() context.Context
- func ListenAndServe(server ListenAndServer, gracePeriod time.Duration)
- func ListenAndServeTLS(server *http.Server, certFile, keyFile string, gracePeriod time.Duration)
- func OnInterrupt(work func())
- func Run(work func(ctx context.Context))
- func Terminate()
- func Tick(work func(), interval func() time.Duration)
- func TickLiteral(work func(), interval time.Duration)
- func WaitForGracefulShutdown()
- type ListenAndServer
- type Shutdownable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Context ¶
Context returns a context that is cancelled when an interrupt hits. Using this context is a weak guarantee that your work will finish before process exit as callers cannot signal that they are finished. Prefer to use Run().
func ListenAndServe ¶
func ListenAndServe(server ListenAndServer, gracePeriod time.Duration)
ListenAndServe runs the HTTP server and handles shutting it down gracefully on interrupts. This function is not blocking. Callers are expected to exit only after WaitForGracefulShutdown returns to ensure all servers have had time to shut down.
func ListenAndServeTLS ¶
ListenAndServeTLS runs the HTTP server and handles shutting it down gracefully on interrupts. This function is not blocking. Callers are expected to exit only after WaitForGracefulShutdown returns to ensure all servers have had time to shut down.
func OnInterrupt ¶
func OnInterrupt(work func())
OnInterrupt ensures that work is done when an interrupt is fired and that we wait for the work to be finished before we consider the process cleaned up. This function is not blocking.
func Run ¶
Run will do work until an interrupt is received, then signal the worker. This function is not blocking. Callers are expected to exit only after WaitForGracefulShutdown returns to ensure all workers have had time to shut down. This is preferable to getting the raw Context as we can ensure that the work is finished before releasing our share of the wait group on shutdown.
func Terminate ¶
func Terminate()
Terminate can be called to trigger a termination to the current process.
func Tick ¶
Tick will do work on a dynamically determined interval until an interrupt is received. This function is not blocking. Callers are expected to exit only after WaitForGracefulShutdown returns to ensure all workers have had time to shut down.
func TickLiteral ¶
TickLiteral runs Tick with an unchanging interval.
func WaitForGracefulShutdown ¶
func WaitForGracefulShutdown()
WaitForGracefulShutdown waits until all registered servers and workers have had time to gracefully shut down, or times out. This function is blocking.
Types ¶
type ListenAndServer ¶
type ListenAndServer interface { Shutdownable ListenAndServe() error }
ListenAndServer is typically an http.Server
type Shutdownable ¶
Shutdownable is typically an http.Server