Documentation
¶
Overview ¶
Package lifecycle manages the goroutines and servers a process owns, so shutdown is orderly rather than abrupt.
A Manager tracks background work and the HTTP server together: on a termination signal it stops accepting new requests, lets in-flight ones finish within a deadline, then cancels the background work. It is built on gopkg.in/tomb.v2.
Index ¶
- type Manager
- func (m *Manager) Dying() <-chan struct{}
- func (m *Manager) Go(f func() error)
- func (m *Manager) Kill(reason error)
- func (m *Manager) StartBotWithTomb(startFunc func(), stopFunc func())
- func (m *Manager) StartEventSubscriber(subscriberFunc func() error, description string)
- func (m *Manager) StartHTTPServer(server *http.Server, port string)
- func (m *Manager) StartPeriodicTask(interval time.Duration, taskFunc func() error, description string)
- func (m *Manager) Wait() error
- func (m *Manager) WaitForShutdownSignal(server *http.Server, additionalCleanup ...func() error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager provides a centralized way to manage goroutines using tomb.Tomb
func NewManager ¶
NewManager creates a new tomb manager for a service
func (*Manager) Dying ¶
func (m *Manager) Dying() <-chan struct{}
Dying returns a channel that is closed when the tomb is dying
func (*Manager) StartBotWithTomb ¶
func (m *Manager) StartBotWithTomb(startFunc func(), stopFunc func())
StartBotWithTomb starts a bot with tomb management
func (*Manager) StartEventSubscriber ¶
StartEventSubscriber starts an event subscriber managed by tomb
func (*Manager) StartHTTPServer ¶
StartHTTPServer starts an HTTP server managed by tomb
func (*Manager) StartPeriodicTask ¶
func (m *Manager) StartPeriodicTask(interval time.Duration, taskFunc func() error, description string)
StartPeriodicTask starts a periodic task managed by tomb
func (*Manager) Wait ¶
Wait waits for all managed goroutines to finish.
It returns immediately when none were ever started. tomb closes the channel Wait blocks on only from inside a finishing goroutine, so waiting on a tomb that never had one blocks forever — which would hang shutdown for a service that registered no background work.