Skip to content

Commit

Permalink
clean up init and TestMode
Browse files Browse the repository at this point in the history
  • Loading branch information
gfr10598 committed Oct 29, 2019
1 parent 4ba55f0 commit be5835d
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions cmd/gardener/gardener.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ import (
_ "expvar"
)

func init() {
// Always prepend the filename and line number.
log.SetFlags(log.LstdFlags | log.Lshortfile)
}

// Environment provides "global" variables.
// Any env vars that we want to read only at startup should be stored here.
type environment struct {
Expand All @@ -56,9 +61,6 @@ type environment struct {
NumQueues int
StartDate time.Time // The archive date to start reprocessing.
DateSkip int // Number of dates to skip between PostDay, to allow rapid scanning in sandbox.

// TestMode is used to change behavior for unit tests.
TestMode bool
}

// env provides environment vars.
Expand Down Expand Up @@ -163,14 +165,6 @@ func LoadEnv() {
}
}

func init() {
// HACK This allows some modified behavior when running unit tests.
if flag.Lookup("test.v") != nil {
env.TestMode = true
}
LoadEnv()
}

// ###############################################################################
// Batch processing task scheduling and support code
// ###############################################################################
Expand Down Expand Up @@ -272,11 +266,6 @@ func jobServer(w http.ResponseWriter, r *http.Request) {
// Main
// ###############################################################################

func init() {
// Always prepend the filename and line number.
log.SetFlags(log.LstdFlags | log.Lshortfile)
}

func handleSigTerm() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Kill)
Expand All @@ -290,11 +279,9 @@ func handleSigTerm() {
}

func main() {
flag.Parse()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
flag.Parse() // For prometheus listen address.

LoadEnv()
if env.Error != nil {
log.Println(env.Error)
log.Println(env)
Expand All @@ -316,12 +303,18 @@ func main() {

switch env.ServiceMode {
case "manager":
// This is new new "manager" mode, in which Gardener provides /job and /update apis
// for parsers to get work and report progress.
handleSigTerm()
http.HandleFunc("/job", jobServer) // healthCheck works correctly
healthy = true
log.Println("Running as manager service")
case "legacy":
// This is the "legacy" mode, that manages work through task queues.
// TODO - this creates a storage client, which should be closed on termination.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

th, err := taskHandlerFromEnv(ctx, http.DefaultClient)

if err != nil {
Expand Down

0 comments on commit be5835d

Please sign in to comment.