cmd/chihaya: stop hooks

Fixes #214.
This commit is contained in:
Leo Balduf
2016-09-24 13:38:05 -04:00
parent c1b7ba4a52
commit 86ebb108fc
3 changed files with 41 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/chihaya/chihaya/bittorrent"
"github.com/chihaya/chihaya/frontend"
"github.com/chihaya/chihaya/stopper"
"github.com/chihaya/chihaya/storage"
)
@@ -94,3 +95,25 @@ func (l *Logic) AfterScrape(ctx context.Context, req *bittorrent.ScrapeRequest,
}
}
}
// Stop stops the Logic.
//
// This stops any hooks that implement stopper.Stopper.
func (l *Logic) Stop() []error {
stopGroup := stopper.NewStopGroup()
for _, hook := range l.preHooks {
stoppable, ok := hook.(stopper.Stopper)
if ok {
stopGroup.Add(stoppable)
}
}
for _, hook := range l.postHooks {
stoppable, ok := hook.(stopper.Stopper)
if ok {
stopGroup.Add(stoppable)
}
}
return stopGroup.Stop()
}