Skip to content

Commit

Permalink
various PR feedback fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory Russell committed Dec 17, 2019
1 parent 5eab484 commit 20214a5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
5 changes: 2 additions & 3 deletions cmd/gardener/gardener.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"github.com/m-lab/go/prometheusx"
"github.com/m-lab/go/rtx"

"github.com/m-lab/etl-gardener/cloud"
job "github.com/m-lab/etl-gardener/job-service"
Expand Down Expand Up @@ -288,9 +289,7 @@ func main() {
// This is new new "manager" mode, in which Gardener provides /job and /update apis
// for parsers to get work and report progress.
svc, err := job.NewJobService(time.Date(2009, 2, 1, 0, 0, 0, 0, time.UTC))
if err != nil {
log.Fatal("Could not initialize job service")
}
rtx.Must(err, "Could not initialize job service")
http.HandleFunc("/job", svc.JobHandler)
healthy = true
log.Println("Running as manager service")
Expand Down
27 changes: 19 additions & 8 deletions cmd/gardener/gardener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import (
"context"
_ "expvar"
"io/ioutil"
"log"
"net/http"
"os"
"testing"
"time"

"github.com/m-lab/go/osx"
)

func TestLegacyModeSetup(t *testing.T) {
Expand All @@ -25,10 +28,8 @@ func TestLegacyModeSetup(t *testing.T) {
"START_DATE": "20090220",
}
for k, v := range vars {
err := os.Setenv(k, v)
if err != nil {
t.Fatal(err)
}
cleanup := osx.MustSetenv(k, v)
defer cleanup()
}

LoadEnv()
Expand All @@ -46,10 +47,8 @@ func TestManagerMode(t *testing.T) {
"ARCHIVE_BUCKET": "archive-mlab-testing",
}
for k, v := range vars {
err := os.Setenv(k, v)
if err != nil {
t.Fatal(err)
}
cleanup := osx.MustSetenv(k, v)
defer cleanup()
}

go main()
Expand All @@ -64,3 +63,15 @@ func TestManagerMode(t *testing.T) {
t.Fatal(string(data))
}
}

func TestEnv(t *testing.T) {
vars := map[string]string{
"SERVICE_MODE": "manager",
"PROJECT": "foobar",
"ARCHIVE_BUCKET": "archive-mlab-testing",
}
for k := range vars {
v := os.Getenv(k)
log.Println(k, v)
}
}
12 changes: 7 additions & 5 deletions job-service/job-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import (
type Service struct {
lock sync.Mutex

startDate time.Time // The date to restart at.
date time.Time // The date currently being dispatched.
dateFilter *regexp.Regexp // filter to apply to dates.
jobTypes []tracker.Job // The job prefixes to be iterated through.
nextIndex int // index of TypeSource to dispatch next.
startDate time.Time // The date to restart at.
date time.Time // The date currently being dispatched.
// Filter to apply to dates if we want to process a subset for sanity checking.
// For production, this will always be nil.
dateFilter *regexp.Regexp
jobTypes []tracker.Job // The job prefixes to be iterated through.
nextIndex int // index of TypeSource to dispatch next.
}

func (svc *Service) advanceDate() {
Expand Down
9 changes: 4 additions & 5 deletions job-service/job-service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import (
"github.com/m-lab/etl-gardener/tracker"
)

func now() time.Time {
return time.Date(2011, 2, 6, 1, 2, 3, 4, time.UTC)
}

func TestService_NextJob(t *testing.T) {
monkey.Patch(time.Now, now)
// This allows predictable behavior from time.Since in the advanceDate function.
monkey.Patch(time.Now, func() time.Time {
return time.Date(2011, 2, 6, 1, 2, 3, 4, time.UTC)
})
defer monkey.Unpatch(time.Now)

start := time.Date(2011, 2, 3, 5, 6, 7, 8, time.UTC)
Expand Down

0 comments on commit 20214a5

Please sign in to comment.