diff --git a/broker/broker.go b/broker/broker.go index 6b36019..430a06f 100644 --- a/broker/broker.go +++ b/broker/broker.go @@ -20,7 +20,7 @@ var authlimiter = rate.NewLimiter(rate.Limit(1.0/60.0), 1) var limiter = rate.NewLimiter(rate.Limit(1.0/20.0), 1) type Broker interface { - Search([]config.State) ([]Job, error) + SearchStates([]config.State) ([]Job, error) } func do(r *http.Request) (*http.Response, error) { diff --git a/broker/fastexact.go b/broker/fastexact.go index 4e955f2..12961f9 100644 --- a/broker/fastexact.go +++ b/broker/fastexact.go @@ -38,13 +38,13 @@ func (fe FastExact) WithMock() FastExact { return fe } -func (fe FastExact) Search(states []config.State) ([]Job, error) { - jobs, err := fe.search(states) +func (fe FastExact) SearchStates(states []config.State) ([]Job, error) { + jobs, err := fe.searchStates(states) if err == ErrNoAuth { if err := fe.login(); err != nil { return nil, err } - jobs, err = fe.search(states) + jobs, err = fe.searchStates(states) } return jobs, err } @@ -91,7 +91,7 @@ func (fe FastExact) setHeaders(req *http.Request) { req.Header.Set("Content-Type", "application/x-www-form-urlencoded") } -func (fe FastExact) search(states []config.State) ([]Job, error) { +func (fe FastExact) searchStates(states []config.State) ([]Job, error) { var jobs []Job for _, state := range states { subjobs, err := fe.searchOne(state) diff --git a/broker/fastexact_test.go b/broker/fastexact_test.go index add5dca..7d1dce4 100644 --- a/broker/fastexact_test.go +++ b/broker/fastexact_test.go @@ -34,7 +34,7 @@ func TestFastExactReal(t *testing.T) { if err := fe.login(); err != nil { t.Fatal(err) } - jobs, err := fe.search(states) + jobs, err := fe.searchStates(states) if err != nil { t.Fatal(err) } @@ -56,14 +56,14 @@ func TestFastExactLogin(t *testing.T) { } } -func TestFastExactSearch(t *testing.T) { +func TestFastExactSearchStates(t *testing.T) { logtr.SetLevel(logtr.SOS) limiter = rate.NewLimiter(rate.Limit(60.0), 1) fe := NewFastExact().WithMock() _ = fe db := storage.NewMap() _ = db - if jobs, err := fe.search([]config.State{config.State("NC"), config.State("SC")}); err != nil { + if jobs, err := fe.searchStates([]config.State{config.State("NC"), config.State("SC")}); err != nil { t.Fatal(err) } else if len(jobs) != 10 { t.Fatal(len(jobs)) diff --git a/broker/ntgvision.go b/broker/ntgvision.go index 1d3bdf4..8abd732 100644 --- a/broker/ntgvision.go +++ b/broker/ntgvision.go @@ -15,7 +15,7 @@ import ( type NTGVision struct { searcher interface { - search(states []config.State) (io.ReadCloser, error) + searchStates(states []config.State) (io.ReadCloser, error) searchJobReadCloser(id int64) (io.ReadCloser, error) } } @@ -187,8 +187,8 @@ func (ntg NTGVision) searchJob(id int64) (ntgVisionJobInfo, error) { return result, err } -func (ntg NTGVision) Search(states []config.State) ([]Job, error) { - rc, err := ntg.searcher.search(states) +func (ntg NTGVision) SearchStates(states []config.State) ([]Job, error) { + rc, err := ntg.searcher.searchStates(states) if err != nil { return nil, err } @@ -226,20 +226,20 @@ func setNTGToken(token string) { db.Set(getNTGTokenKey(), []byte(token)) } -func (ntg NTGVision) search(states []config.State) (io.ReadCloser, error) { +func (ntg NTGVision) searchStates(states []config.State) (io.ReadCloser, error) { if getNTGToken() == "" { logtr.Debugf("NTG token is empty, refreshing ntg auth") if err := ntg.refreshAuth(); err != nil { return nil, err } } - rc, err := ntg._search(states) + rc, err := ntg._searchStates(states) if err == ErrNoAuth { logtr.Debugf("err no auth on search, refreshing ntg auth") if err := ntg.refreshAuth(); err != nil { return nil, err } - rc, err = ntg._search(states) + rc, err = ntg._searchStates(states) } return rc, err } @@ -285,7 +285,7 @@ func (ntg NTGVision) _refreshAuth() error { return nil } -func (ntg NTGVision) _search(states []config.State) (io.ReadCloser, error) { +func (ntg NTGVision) _searchStates(states []config.State) (io.ReadCloser, error) { request, err := ntg.newRequest(states) if err != nil { return nil, err diff --git a/broker/ntgvision_mock.go b/broker/ntgvision_mock.go index e9f452b..7a08769 100644 --- a/broker/ntgvision_mock.go +++ b/broker/ntgvision_mock.go @@ -15,7 +15,7 @@ func NewNTGVisionMock() NTGVisionMock { return NTGVisionMock{} } -func (ntgm NTGVisionMock) search(states []config.State) (io.ReadCloser, error) { +func (ntgm NTGVisionMock) searchStates(states []config.State) (io.ReadCloser, error) { path := path.Join(os.Getenv("GOPATH"), "src", "local", "truckstop", "broker", "testdata", "ntgvision_response.json") b, err := ioutil.ReadFile(path) return io.NopCloser(bytes.NewReader(b)), err diff --git a/config/config.go b/config/config.go index 6c82d72..d515a12 100644 --- a/config/config.go +++ b/config/config.go @@ -121,11 +121,11 @@ func AllZips() []string { zipm := map[string]struct{}{} for _, v := range Clients(time.Now().Add(time.Hour * 24 * 365)) { for _, state := range v.Zips { - statem[state] = struct{}{} + zipm[state] = struct{}{} } } - zips := make([]State, 0, len(statem)+1) - for k := range statem { + zips := make([]string, 0, len(zipm)+1) + for k := range zipm { zips = append(zips, k) } return zips diff --git a/main.go b/main.go index 2a01a34..cc80a1c 100644 --- a/main.go +++ b/main.go @@ -145,7 +145,7 @@ func matrixrecv() error { } } if err := db.Set(key, []byte{'k'}); err != nil { - logtr.Errorf("failed to mark state gathered @%s: %v", key, err) + logtr.Errorf("failed to mark pause gathered @%s: %v", key, err) } } setNewPauses(pauses) @@ -313,6 +313,10 @@ func once() error { } func getJobs() ([]broker.Job, error) { + return getJobsStates() +} + +func getJobsStates() ([]broker.Job, error) { states := config.AllStates() brokers := []broker.Broker{} if config.Get().Brokers.NTG.Enabled { @@ -326,7 +330,7 @@ func getJobs() ([]broker.Job, error) { logtr.Debugf("brokers=%+v", brokers) jobs := []broker.Job{} for _, broker := range brokers { - somejobs, err := broker.Search(states) + somejobs, err := broker.SearchStates(states) if err != nil { return nil, err }