14360: Add explicit Start method to dispatcher.
authorTom Clegg <tclegg@veritasgenetics.com>
Sat, 27 Oct 2018 00:09:09 +0000 (20:09 -0400)
committerTom Clegg <tclegg@veritasgenetics.com>
Sat, 27 Oct 2018 00:09:09 +0000 (20:09 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

lib/dispatchcloud/cmd.go
lib/dispatchcloud/dispatcher.go

index a5a11d2fa33d378521d75c139672282f7bc128b3..92948fb300e703971e59957b4f6f98db176a42ef 100644 (file)
@@ -13,5 +13,7 @@ import (
 var Command cmd.Handler = service.Command(arvados.ServiceNameDispatchCloud, newHandler)
 
 func newHandler(cluster *arvados.Cluster, _ *arvados.NodeProfile) service.Handler {
-       return &dispatcher{Cluster: cluster}
+       d := &dispatcher{Cluster: cluster}
+       go d.Start()
+       return d
 }
index e422b3963d1d66bcc523271fde25aba3d5a0137f..707c31f249e50ae176708499cefff6013d6b7aa1 100644 (file)
@@ -58,22 +58,28 @@ type dispatcher struct {
        stop      chan struct{}
 }
 
+// Start starts the dispatcher. Start can be called multiple times
+// with no ill effect.
+func (disp *dispatcher) Start() {
+       disp.setupOnce.Do(disp.setup)
+}
+
 // ServeHTTP implements service.Handler.
 func (disp *dispatcher) ServeHTTP(w http.ResponseWriter, r *http.Request) {
-       disp.setupOnce.Do(disp.setup)
+       disp.Start()
        disp.httpHandler.ServeHTTP(w, r)
 }
 
 // CheckHealth implements service.Handler.
 func (disp *dispatcher) CheckHealth() error {
-       disp.setupOnce.Do(disp.setup)
+       disp.Start()
        return nil
 }
 
 // Stop dispatching containers and release resources. Typically used
 // in tests.
 func (disp *dispatcher) Close() {
-       disp.setupOnce.Do(disp.setup)
+       disp.Start()
        select {
        case disp.stop <- struct{}{}:
        default: