only do ntgvision searches 9-4 EST because 417s mean unauth until forced pw reset
parent
5d4677ab5c
commit
6551fb906d
|
|
@ -221,7 +221,30 @@ func (ntg NTGVision) SearchZips(zips []string) ([]Job, error) {
|
|||
return jobs, nil
|
||||
}
|
||||
|
||||
func (ntg NTGVision) workingHours(now time.Time) bool {
|
||||
// TODO assert M-F 9-4 EST
|
||||
location, err := time.LoadLocation("EST")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
now = now.In(location)
|
||||
switch now.Weekday() {
|
||||
case time.Sunday, time.Saturday:
|
||||
return false
|
||||
}
|
||||
switch now.Hour() {
|
||||
case 9, 10, 11, 12, 13, 14, 15, 16:
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (ntg NTGVision) SearchStates(states []config.State) ([]Job, error) {
|
||||
if ntg.workingHours(time.Now()) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
rc, err := ntg.searcher.searchStates(states)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -334,7 +357,7 @@ func (ntg NTGVision) _searchStates(states []config.State) (io.ReadCloser, error)
|
|||
request2, _ := ntg.newRequest(states)
|
||||
requestb, _ := ioutil.ReadAll(request2.Body)
|
||||
logtr.Debugf("ntg auth bad status: url=%s, status=%v, body=%s, headers=%+v, request=%+v, requestb=%s", request.URL.String(), resp.StatusCode, b, resp.Header, request2, requestb)
|
||||
if resp.StatusCode > 400 && resp.StatusCode < 404 {
|
||||
if resp.StatusCode > 400 && resp.StatusCode < 404 || resp.StatusCode == 417 { // TODO wtf is 417 for
|
||||
logtr.Debugf("ntg auth bad status: err no auth")
|
||||
return nil, ErrNoAuth
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package broker
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestWorkingHoursNTG(t *testing.T) {
|
||||
ntg := NTGVision{}
|
||||
if !ntg.workingHours(time.Date(2022, 1, 27, 12, 0, 0, 0, time.Local)) {
|
||||
t.Fatal("noon MST not ok")
|
||||
}
|
||||
if ntg.workingHours(time.Date(2022, 1, 27, 23, 0, 0, 0, time.Local)) {
|
||||
t.Fatal("midnight MST ok")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue