https://github.com/pumpkinseed/shutdown
Graceful shutdown package for Go
https://github.com/pumpkinseed/shutdown
graceful-shutdown microservice reliability shutdown shutdown-manager
Last synced: 3 months ago
JSON representation
Graceful shutdown package for Go
- Host: GitHub
- URL: https://github.com/pumpkinseed/shutdown
- Owner: PumpkinSeed
- License: apache-2.0
- Created: 2019-07-23T09:46:36.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-09-05T09:37:06.000Z (about 6 years ago)
- Last Synced: 2025-07-03T02:03:24.668Z (3 months ago)
- Topics: graceful-shutdown, microservice, reliability, shutdown, shutdown-manager
- Language: Go
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# shutdown
Graceful shutdown package for Go services with built-in healthcheck for persistent dependencies.
# Usage
### Shutdown
Everything what depends on the graceful shutdown (ex.: long-time file writes, database connection, http requests), most implement the `ServiceDescriptor` interface.
```go
package example
type ServiceDescriptor interface {
Stop() error
Ping() error
Reconnect() error
}
```Also the constructor requires a logging instance with the following interface implementation.
```go
package example
type Log interface {
Errorf(format string, args ...interface{})
Infof(format string, args ...interface{})
Debugf(format string, args ...interface{})
Warnf(format string, args ...interface{})
}
```Create a new instance of the shutdown and adding new services and call the `GracefulExit` handler.
```go
package examplehandler := shutdown.NewHandler(&testLog{t})
handler.Add("service1", "", shutdown.Init, &service1)
wg := &sync.WaitGroup{}
shutdown.GracefuleExit(handler, wg)wg.Wait()
```Determine the sequence of the shutdown when we add them into the list.
```go
package examplehandler := shutdown.NewHandler(&testLog{t})
handler.Add("service1", "", shutdown.Init, &service1)
handler.Add("service2", "service1", shutdown.Before, &service2)
handler.Add("service3", "service2", shutdown.After, &service3)
wg := &sync.WaitGroup{}
shutdown.GracefuleExit(handler, wg)
```### Important
Healthcheck not fully implemented yet!