From e78dc74990e78a4a9ebcb2a1979e66aa4b017ca7 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Mon, 21 Jul 2014 03:54:22 -0400 Subject: [PATCH] added Close to tracker --- http/http.go | 4 ++++ tracker/tracker.go | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/http/http.go b/http/http.go index 40c2292..71b42cf 100644 --- a/http/http.go +++ b/http/http.go @@ -80,4 +80,8 @@ func Serve(cfg *config.Config, tkr *tracker.Tracker) { glog.V(0).Info("Starting on ", cfg.Addr) graceful.Run(cfg.Addr, cfg.RequestTimeout.Duration, newRouter(srv)) + err := srv.tracker.Close() + if err != nil { + glog.Errorf("Failed to shutdown tracker cleanly: %s", err.Error()) + } } diff --git a/tracker/tracker.go b/tracker/tracker.go index 0c92456..b4c4b34 100644 --- a/tracker/tracker.go +++ b/tracker/tracker.go @@ -51,6 +51,21 @@ func New(cfg *config.Config) (*Tracker, error) { }, nil } +// Close gracefully shutdowns a Tracker by closing any database connections. +func (tkr *Tracker) Close() (err error) { + err = tkr.Pool.Close() + if err != nil { + return + } + + err = tkr.backend.Close() + if err != nil { + return + } + + return +} + // Writer serializes a tracker's responses, and is implemented for each // response transport used by the tracker. //