Skip to content

Commit 741b483

Browse files
committed
added hook for custom shutdown
1 parent 6665d82 commit 741b483

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

app.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@ var (
2727

2828
// App specifies functions to control passed HTTP servers.
2929
type App struct {
30-
// PreServeFn is a common hook notifies client that all servers is
30+
// PreServeFn is a common hook notifies client that all servers are
3131
// about to start serving.
3232
PreServeFn func(inherited bool) error
33+
34+
// CompleteShutdownFn is a parent's hook, a part of shutdown process
35+
// that allows client to do extra work after all http servers will
36+
// be shutdown. All dependent resources can be closed here.
37+
//
38+
// For stateful services: and before child will start serving.
39+
CompleteShutdownFn func()
40+
3341
// PreParentExitFn is a child's hook that allows client to do
34-
// something on a child's side before the parent will exit.
42+
// extra work on a child's side before the parent will exit.
3543
//
3644
// Useful e.g. for updating pid in a pid file while acting
3745
// as a systemd's service.
@@ -47,6 +55,7 @@ type App struct {
4755
func NewApp(servers ...*http.Server) *App {
4856
a := &App{
4957
PreServeFn: func(inherited bool) error { return nil },
58+
CompleteShutdownFn: func() {},
5059
PreParentExitFn: func() {},
5160
servers: servers,
5261
waitChildTimeout: time.Second * 60,
@@ -110,6 +119,7 @@ func (a *App) Shutdown() {
110119
}
111120

112121
wg.Wait()
122+
a.CompleteShutdownFn()
113123
}
114124

115125
// ListenAndServe creates listeners for the given servers or reuses

0 commit comments

Comments
 (0)