Compare commits

..

5 Commits

Author SHA1 Message Date
Bel LaPointe
550ce91a7f accept more noauth codes from ntg 2022-01-11 08:35:07 -05:00
Bel LaPointe
9d8f561b54 logs 2022-01-11 08:24:46 -05:00
Bel LaPointe
e12299ac20 add config name for identifying who wants what 2022-01-11 08:16:02 -05:00
Bel LaPointe
29ae26153f add logs 2022-01-11 07:58:08 -05:00
Bel LaPointe
8109bb3fa0 sleep on start before getting email 2022-01-11 07:57:11 -05:00
6 changed files with 14 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ package broker
import (
"fmt"
"local/truckstop/config"
"time"
)
@@ -37,7 +38,8 @@ func (j JobLocation) String() string {
func (j Job) FormatMultilineText() string {
return fmt.Sprintf(
"--- %s => %s ---\nPickup: %s\nDropoff: %s\nNotes: %d lbs, %d miles, %s",
"--- %s: %s => %s ---\nPickup: %s\nDropoff: %s\nNotes: %d lbs, %d miles, %s",
config.Get().Name,
j.Pickup.State,
j.Dropoff.State,
j.Pickup.String(),

View File

@@ -146,7 +146,7 @@ func (ntg NTGVision) _search(states []config.State) (io.ReadCloser, error) {
if resp.StatusCode != http.StatusOK {
b, _ := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if resp.StatusCode > 400 && resp.StatusCode < 404 {
if resp.StatusCode > 400 && resp.StatusCode < 500 && resp.StatusCode != 404 && resp.StatusCode != 410 {
return nil, ErrNoAuth
}
return nil, fmt.Errorf("bad status searching ntg: %d: %s", resp.StatusCode, b)

View File

@@ -1,4 +1,5 @@
{
"Name": "pa",
"Interval": {
"OK": "6h0m0s",
"Error": "6h",

View File

@@ -10,6 +10,7 @@ import (
)
type Config struct {
Name string
Interval struct {
Email Duration
OK Duration

View File

@@ -22,6 +22,7 @@ func main() {
lock := &sync.Mutex{}
go func() {
for {
time.Sleep(config.Get().Interval.Email.Get())
if config.Get().EmailerEnabled {
lock.Lock()
if err := email(); err != nil {
@@ -29,7 +30,6 @@ func main() {
}
lock.Unlock()
}
time.Sleep(config.Get().Interval.Email.Get())
}
}()
if err := _main(); err != nil {
@@ -110,12 +110,15 @@ func _main() error {
}
func _mainOne() error {
log.Println("config.refreshing...")
if err := config.Refresh(); err != nil {
return err
}
log.Println("once...")
if err := once(); err != nil {
return err
}
log.Println("/_mainOne")
return nil
}
@@ -136,6 +139,7 @@ func once() error {
if err := sendJob(jobs[i]); err != nil {
return err
}
log.Println("sent job", jobs[i])
if err := config.Get().DB().Set(jobs[i].ID, []byte(`sent`)); err != nil {
return err
}

View File

@@ -3,9 +3,11 @@ todo:
subtasks:
- banlist criteria like vendors, brokers, metadata
- quiet hours
- setup pa on element
- setup ma on element
- accept states via element for one system
- set up copy for caleb, broc
done:
- setup pa on element
- configurable email interval
- jitter on intervals, including dedicated err span
- email doesnt get all matches