and nop notifier
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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{}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user