Browse Source

vendor: Update github.com/thejerf/suture

Jakob Borg 7 years ago
parent
commit
c884955ff7

+ 3 - 2
vendor/github.com/thejerf/suture/messages.go

@@ -41,12 +41,13 @@ type serviceFailed struct {
 
 func (sf serviceFailed) isSupervisorMessage() {}
 
-func (s *Supervisor) serviceEnded(id serviceID) {
-	s.sendControl(serviceEnded{id})
+func (s *Supervisor) serviceEnded(id serviceID, complete bool) {
+	s.sendControl(serviceEnded{id, complete})
 }
 
 type serviceEnded struct {
 	id serviceID
+	complete bool
 }
 
 func (s serviceEnded) isSupervisorMessage() {}

+ 22 - 0
vendor/github.com/thejerf/suture/service.go

@@ -58,8 +58,30 @@ If you implement the fmt.Stringer interface, that will be used.
 If you do not implement the fmt.Stringer interface, a default
 fmt.Sprintf("%#v") will be used.
 
+Optional Interface
+
+Services may optionally implement IsCompletable, which allows a service
+to indicate to a supervisor that it does not need to be restarted if
+it has terminated.
+
 */
 type Service interface {
 	Serve()
 	Stop()
 }
+
+/*
+
+IsCompletable is an optionally-implementable interface that allows a service
+to report to a supervisor that it does not need to be restarted because it
+has terminated normally. When a Service is going to be restarted, the
+supervisor will check for this method, and if Complete returns true, the
+service is removed from the supervisor instead of restarted.
+
+This is only executed when the service is not running because it has
+terminated, and has not yet been restarted.
+
+*/
+type IsCompletable interface {
+	Complete() bool
+}

+ 16 - 4
vendor/github.com/thejerf/suture/supervisor.go

@@ -403,7 +403,14 @@ func (s *Supervisor) Serve() {
 			case serviceEnded:
 				service, monitored := s.services[msg.id]
 				if monitored {
-					s.handleFailedService(msg.id, fmt.Sprintf("%s returned unexpectedly", service), []byte("[unknown stack trace]"))
+					if msg.complete {
+						delete(s.services, msg.id)
+						go func() {
+							service.Service.Stop()
+						}()
+					} else {
+						s.handleFailedService(msg.id, fmt.Sprintf("%s returned unexpectedly", service), []byte("[unknown stack trace]"))
+					}
 				}
 			case addService:
 				id := s.serviceCounter
@@ -524,7 +531,12 @@ func (s *Supervisor) runService(service Service, id serviceID) {
 
 		service.Serve()
 
-		s.serviceEnded(id)
+		complete := false
+		if completable, ok := service.(IsCompletable); ok && completable.Complete() {
+			complete = true
+		}
+
+		s.serviceEnded(id, complete)
 	}()
 }
 
@@ -534,10 +546,10 @@ func (s *Supervisor) removeService(id serviceID, notificationChan chan struct{},
 		delete(s.services, id)
 		s.servicesShuttingDown[id] = namedService
 		go func() {
-			successChan := make(chan bool)
+			successChan := make(chan struct{})
 			go func() {
 				namedService.Service.Stop()
-				successChan <- true
+				close(successChan)
 				if notificationChan != nil {
 					notificationChan <- struct{}{}
 				}

+ 1 - 1
vendor/manifest

@@ -476,7 +476,7 @@
 			"importpath": "github.com/thejerf/suture",
 			"repository": "https://github.com/thejerf/suture",
 			"vcs": "git",
-			"revision": "87e298c9891673c9ae76e10c2c9be589127e5f49",
+			"revision": "3f1fb62fe0a3cc6429122d7dc45588a8b59c5bb6",
 			"branch": "master",
 			"notests": true
 		},