Compare commits

..

5 Commits

Author SHA1 Message Date
bel
c62d84b40a cache last ntg result for off hours 2022-01-29 18:59:16 -07:00
bel
1a072fee59 Merge branch 'master' of http://gogs.scratch.com:59515/bel/truckstop 2022-01-29 18:44:21 -07:00
bel
c4213e697d fuck backwards bool 2022-01-29 18:44:13 -07:00
bel
934a306bc9 log 2022-01-29 18:40:13 -07:00
Bel LaPointe
82bdbb1f3b todo 2022-01-27 20:18:13 -07:00
2 changed files with 22 additions and 6 deletions

View File

@@ -224,6 +224,7 @@ func (ntg NTGVision) SearchZips(zips []string) ([]Job, error) {
func (ntg NTGVision) workingHours(now time.Time) bool {
// TODO assert M-F 9-4 EST
now = now.In(time.FixedZone("EST", -5*60*60))
logtr.Debugf("ntg.workingHours: %s: weekday=%v (sun=%v, sat=%v), hour=%v (ok=9..16)", now.String(), now.Weekday(), time.Sunday, time.Saturday, now.Hour())
switch now.Weekday() {
case time.Sunday, time.Saturday:
return false
@@ -237,8 +238,12 @@ func (ntg NTGVision) workingHours(now time.Time) bool {
}
func (ntg NTGVision) SearchStates(states []config.State) ([]Job, error) {
if ntg.workingHours(time.Now()) {
return nil, nil
if !ntg.workingHours(time.Now()) {
lastNtgB, _ := config.Get().DB().Get("ntg_last_search_states")
var jobs []Job
json.Unmarshal(lastNtgB, &jobs)
logtr.Verbosef("ntg.SearchStates: outside of working hours so returning ntg_last_search_states: %+v", jobs)
return jobs, nil
}
rc, err := ntg.searcher.searchStates(states)
@@ -256,12 +261,22 @@ func (ntg NTGVision) SearchStates(states []config.State) ([]Job, error) {
var ntgjobs []ntgVisionJob
err = json.Unmarshal(b, &ntgjobs)
if err != nil {
return nil, err
}
jobs := make([]Job, len(ntgjobs))
for i := range jobs {
jobs[i] = ntgjobs[i].Job()
}
return jobs, err
jobsB, err := json.Marshal(jobs)
if err == nil {
config.Get().DB().Set("ntg_last_search_states", jobsB)
logtr.Verbosef("ntg.SearchStates: in working hours so setting ntg_last_search_states: %+v", jobs)
}
return jobs, nil
}
func getNTGTokenKey() string {

View File

@@ -1,7 +1,4 @@
todo:
- fast exact does not use ID in UID because they spammy
- from states to zip codes w/ range
- modify old items once no longer available; drop stale jobs good candidate but requires new matrix interaction
- more than NTG; blue one
- !states emits current state
- test each !command callbacks to matrix
@@ -14,7 +11,11 @@ todo:
subtasks:
- banlist criteria like vendors, brokers, metadata
- set up copy for caleb, broc
- move from main() and make more functions
done:
- modify old items once no longer available; drop stale jobs good candidate but requires new matrix interaction
- from states to zip codes w/ range
- fast exact does not use ID in UID because they spammy
- fast exact is dumb or...?
- try search ntg by autoinc?
- TEST. Just like, refactor and test to shit.