You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/12/17 07:40:04 UTC

[servicecomb-service-center] 01/01: SCB-1049 call init when new notifyservice instance

This is an automated email from the ASF dual-hosted git repository.

littlecui pushed a commit to branch alarm
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git

commit 3fa06b3de0f5157c732bf22695689f49b80f2306
Author: little-cui <su...@qq.com>
AuthorDate: Mon Dec 17 15:39:41 2018 +0800

    SCB-1049 call init when new notifyservice instance
---
 pkg/notify/notification_service.go | 12 ++++--------
 pkg/notify/notification_test.go    |  3 ++-
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/pkg/notify/notification_service.go b/pkg/notify/notification_service.go
index 47c8a0d..c2edd24 100644
--- a/pkg/notify/notification_service.go
+++ b/pkg/notify/notification_service.go
@@ -43,7 +43,6 @@ func (s *NotifyService) Start() {
 	s.isClose = false
 	s.closeMux.Unlock()
 
-	s.init()
 	// 错误subscriber清理
 	s.AddSubscriber(NewNotifyServiceHealthChecker())
 
@@ -58,15 +57,10 @@ func (s *NotifyService) AddSubscriber(n Subscriber) error {
 		log.Errorf(err, "add subscriber failed")
 		return err
 	}
-	if s.Closed() {
-		err := errors.New("server is shutting down")
-		log.Errorf(err, "add %s subscriber[%s/%s] failed", n.Type(), n.Subject(), n.Group())
-		return err
-	}
 
 	p, ok := s.processors[n.Type()]
 	if !ok {
-		err := errors.New("Unknown subscribe type")
+		err := errors.New("unknown subscribe type")
 		log.Errorf(err, "add %s subscriber[%s/%s] failed", n.Type(), n.Subject(), n.Group())
 		return err
 	}
@@ -135,8 +129,10 @@ func (s *NotifyService) Stop() {
 }
 
 func NewNotifyService() *NotifyService {
-	return &NotifyService{
+	ns := &NotifyService{
 		processors: make(map[Type]*Processor),
 		isClose:    true,
 	}
+	ns.init()
+	return ns
 }
diff --git a/pkg/notify/notification_test.go b/pkg/notify/notification_test.go
index af9e803..f130c27 100644
--- a/pkg/notify/notification_test.go
+++ b/pkg/notify/notification_test.go
@@ -22,6 +22,8 @@ import (
 )
 
 func TestGetNotifyService(t *testing.T) {
+	INSTANCE := RegisterType("INSTANCE", 1)
+
 	notifyService := NewNotifyService()
 	if notifyService == nil {
 		t.Fatalf("TestGetNotifyService failed")
@@ -39,7 +41,6 @@ func TestGetNotifyService(t *testing.T) {
 		t.Fatalf("TestGetNotifyService failed")
 	}
 
-	INSTANCE := RegisterType("INSTANCE", 1)
 	notifyService.Start()
 	notifyService.Start()
 	if notifyService.Closed() != false {