Compare commits

..

4 Commits

Author SHA1 Message Date
bel
0ab534624a NO 2022-01-31 09:31:40 -07:00
bel
b3ce49788b little 2022-01-30 08:43:57 -07:00
bel
bbe839bb88 make working hours, weekdays configurable by impl ntg 2022-01-30 08:34:14 -07:00
bel
60f19968e3 add ntg configurable work hours, weekdays 2022-01-30 08:29:06 -07:00
6 changed files with 50 additions and 10 deletions

View File

@@ -224,14 +224,26 @@ 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:
working := config.Get().Brokers.NTG.Working
logtr.Debugf("ntg.workingHours: now=%s, weekday=%v, hour=%v (ok=%+v)", now.String(), now.Weekday(), now.Hour(), working)
if ok := func() bool {
for _, hr := range working.Hours {
if now.Hour() == hr {
return true
}
}
return false
}(); !ok {
return false
}
switch now.Hour() {
case 9, 10, 11, 12, 13, 14, 15, 16:
default:
if ok := func() bool {
for _, weekday := range working.Weekdays {
if now.Weekday() == time.Weekday(weekday) {
return true
}
}
return false
}(); !ok {
return false
}
return true

View File

@@ -1,11 +1,17 @@
package broker
import (
"local/truckstop/config"
"os"
"testing"
"time"
)
func TestWorkingHoursNTG(t *testing.T) {
os.Setenv("CONFIG", "../config.json")
if err := config.Refresh(nil); err != nil {
t.Fatal(err)
}
ntg := NTGVision{}
if !ntg.workingHours(time.Date(2022, 1, 27, 12, 0, 0, 0, time.FixedZone("MST", -7*60*60))) {
t.Fatal("noon MST not ok")

View File

@@ -79,6 +79,10 @@
"UseZips": true,
"RadiusMiles": 200,
"NTG": {
"Working": {
"Hours": [6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
"Weekdays": [1, 2, 3, 4, 5]
},
"Enabled": false,
"JobInfo": true,
"Mock": true,
@@ -94,4 +98,4 @@
"Password": "166647"
}
}
}
}

View File

@@ -83,6 +83,10 @@
"Password": "p"
},
"NTG": {
"Working": {
"Hours": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23],
"Weekdays": [0, 1, 2, 3, 4, 5, 6]
},
"Enabled": true,
"JobInfo": true,
"Mock": true,

View File

@@ -67,6 +67,10 @@ type Config struct {
UseZips bool
RadiusMiles int
NTG struct {
Working struct {
Hours []int
Weekdays []int
}
Enabled bool
JobInfo bool
Mock bool

16
main.go
View File

@@ -126,7 +126,12 @@ func matrixrecv() error {
logtr.Errorf("failed to mark state gathered @%s: %v", key, err)
}
}
setNewZips(zips)
if config.Get().Brokers.UseZips {
setNewZips(zips)
} else {
sender.Send("I don't accept !zip, only !state right now")
}
}()
func() {
logtr.Verbosef("looking for states")
@@ -150,7 +155,12 @@ func matrixrecv() error {
logtr.Errorf("failed to mark state gathered @%s: %v", key, err)
}
}
setNewStates(states)
if !config.Get().Brokers.UseZips {
setNewStates(states)
} else {
sender.Send("I don't accept !state, only !zip right now")
}
}()
func() {
logtr.Verbosef("looking for radius")
@@ -371,7 +381,7 @@ func __main() error {
logtr.Errorf("failed _main: %v", err)
}
if config.Get().Once {
time.Sleep(3 * time.Second)
time.Sleep(10 * time.Second)
return err
}
if err != nil {