and nop notifier

This commit is contained in:
Umputun
2018-10-26 00:37:58 -05:00
parent cc3786b9e0
commit d80b2d33cb
3 changed files with 17 additions and 5 deletions
+2 -2
View File
@@ -229,7 +229,7 @@ func (s *ServerCommand) newServerApp() (*serverApp, error) {
notifyService, err := s.makeNotify(dataService)
if err != nil {
log.Printf("[WARN] failed to make notify service, %s", err)
notifyService = nil // disable notifier
notifyService = notify.NopService // disable notifier
}
authProviders := s.makeAuthProviders(jwtService, avatarProxy, dataService)
@@ -474,7 +474,7 @@ func (s *ServerCommand) makeNotify(dataStore *service.DataStore) (*notify.Servic
}
return notify.NewService(dataStore, s.Notify.QueueSize, tg), nil
case "none":
return notify.NewService(dataStore, s.Notify.QueueSize), nil
return notify.NopService, nil
}
return nil, errors.Errorf("unsupported notification type %q", s.Notify.Type)
}
+8 -3
View File
@@ -76,9 +76,11 @@ func (s *Service) Submit(comment store.Comment) {
// Close queue channel and wait for completion
func (s *Service) Close() {
close(s.queue)
s.cancel()
<-s.ctx.Done()
if s.queue != nil {
close(s.queue)
s.cancel()
<-s.ctx.Done()
}
s.closed = true
}
@@ -97,3 +99,6 @@ func (s *Service) do() {
wg.Wait()
}
}
// NopService is do-nothing notifier, without destinations
var NopService = &Service{}
+7
View File
@@ -80,6 +80,13 @@ func TestService_Many(t *testing.T) {
assert.True(t, d2.closed)
}
func TestService_Nop(t *testing.T) {
s := NopService
s.Submit(store.Comment{})
s.Close()
assert.True(t, s.closed)
}
type mockDest struct {
data []store.Comment
id int