[ARVADOS] updated: 1.3.0-1620-gac7489475

Git user git at public.curoverse.com
Thu Sep 26 14:22:20 UTC 2019


Summary of changes:
 services/keep-balance/balance_run_test.go |  3 +--
 services/keep-balance/main.go             |  8 ++++++-
 services/keep-balance/server.go           | 40 ++++++++++++++-----------------
 3 files changed, 26 insertions(+), 25 deletions(-)

       via  ac74894758f1b56c449022810b45f833adcfefa7 (commit)
      from  97e49cd63b00855a659b76c65ea5122968cf8635 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit ac74894758f1b56c449022810b45f833adcfefa7
Author: Eric Biagiotti <ebiagiotti at veritasgenetics.com>
Date:   Thu Sep 26 10:22:12 2019 -0400

    14714: Removes context from Server functions. Adds sync.Once to setup
    
    Arvados-DCO-1.1-Signed-off-by: Eric Biagiotti <ebiagiotti at veritasgenetics.com>

diff --git a/services/keep-balance/balance_run_test.go b/services/keep-balance/balance_run_test.go
index 1478e6e2e..3ef3b0007 100644
--- a/services/keep-balance/balance_run_test.go
+++ b/services/keep-balance/balance_run_test.go
@@ -5,7 +5,6 @@
 package main
 
 import (
-	"context"
 	"encoding/json"
 	"fmt"
 	"io"
@@ -319,7 +318,7 @@ func (s *runSuite) newServer(options *RunOptions) *Server {
 		Logger:     options.Logger,
 		Dumper:     options.Dumper,
 	}
-	srv.init(context.Background())
+	srv.setup()
 	return srv
 }
 
diff --git a/services/keep-balance/main.go b/services/keep-balance/main.go
index 606fde498..92ed644b5 100644
--- a/services/keep-balance/main.go
+++ b/services/keep-balance/main.go
@@ -41,14 +41,20 @@ func newHandler(ctx context.Context, cluster *arvados.Cluster, _ string) service
 		debugf = log.Printf
 	}
 
+	if options.Logger == nil {
+		options.Logger = ctxlog.FromContext(ctx)
+	}
+
 	srv := &Server{
 		Cluster:    cluster,
 		ArvClient:  ac,
 		RunOptions: options,
 		Metrics:    newMetrics(),
+		Logger:     options.Logger,
+		Dumper:     options.Dumper,
 	}
 
-	go srv.Start(ctx)
+	srv.Start()
 	return srv
 }
 
diff --git a/services/keep-balance/server.go b/services/keep-balance/server.go
index 23e597c89..3e665a30d 100644
--- a/services/keep-balance/server.go
+++ b/services/keep-balance/server.go
@@ -5,16 +5,15 @@
 package main
 
 import (
-	"context"
 	"net/http"
 	"os"
 	"os/signal"
+	"sync"
 	"syscall"
 	"time"
 
 	"git.curoverse.com/arvados.git/sdk/go/arvados"
 	"git.curoverse.com/arvados.git/sdk/go/auth"
-	"git.curoverse.com/arvados.git/sdk/go/ctxlog"
 	"github.com/julienschmidt/httprouter"
 	"github.com/prometheus/client_golang/prometheus/promhttp"
 	"github.com/sirupsen/logrus"
@@ -48,6 +47,7 @@ type Server struct {
 	Metrics    *metrics
 
 	httpHandler http.Handler
+	setupOnce   sync.Once
 
 	Logger logrus.FieldLogger
 	Dumper logrus.FieldLogger
@@ -64,28 +64,12 @@ func (srv *Server) CheckHealth() error {
 }
 
 // Start sets up and runs the balancer.
-func (srv *Server) Start(ctx context.Context) {
-	srv.init(ctx)
-
-	var err error
-	if srv.RunOptions.Once {
-		_, err = srv.runOnce()
-	} else {
-		err = srv.runForever(nil)
-	}
-	if err != nil {
-		srv.Logger.Error(err)
-	}
+func (srv *Server) Start() {
+	srv.setupOnce.Do(srv.setup)
+	go srv.run()
 }
 
-func (srv *Server) init(ctx context.Context) {
-	if srv.RunOptions.Logger == nil {
-		srv.RunOptions.Logger = ctxlog.FromContext(ctx)
-	}
-
-	srv.Logger = srv.RunOptions.Logger
-	srv.Dumper = srv.RunOptions.Dumper
-
+func (srv *Server) setup() {
 	if srv.Cluster.ManagementToken == "" {
 		srv.httpHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 			http.Error(w, "Management API authentication is not configured", http.StatusForbidden)
@@ -101,6 +85,18 @@ func (srv *Server) init(ctx context.Context) {
 	}
 }
 
+func (srv *Server) run() {
+	var err error
+	if srv.RunOptions.Once {
+		_, err = srv.runOnce()
+	} else {
+		err = srv.runForever(nil)
+	}
+	if err != nil {
+		srv.Logger.Error(err)
+	}
+}
+
 func (srv *Server) runOnce() (*Balancer, error) {
 	bal := &Balancer{
 		Logger:         srv.Logger,

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list