multi-client but one ntg search, nontrivial config.json change

This commit is contained in:
Bel LaPointe
2022-01-11 22:54:18 -05:00
parent 5a4bcecac7
commit e546034c26
8 changed files with 138 additions and 54 deletions

View File

@@ -1,6 +1,12 @@
package broker
import "local/truckstop/config"
import (
"local/truckstop/config"
"golang.org/x/time/rate"
)
var limiter = rate.NewLimiter(rate.Limit(0.3), 1)
type Broker interface {
Search([]config.State) ([]Job, error)

View File

@@ -3,6 +3,8 @@ package broker
import (
"fmt"
"local/truckstop/config"
"log"
"strings"
"time"
)
@@ -37,15 +39,29 @@ func (j JobLocation) String() string {
}
func (j Job) FormatMultilineText() string {
return fmt.Sprintf(
"--- %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(),
j.Dropoff.String(),
j.Weight,
j.Miles,
j.Meta,
)
foo := func(client string) string {
return fmt.Sprintf(
"--- %s: %s => %s ---\nPickup: %s\nDropoff: %s\nNotes: %d lbs, %d miles, %s",
client,
j.Pickup.State,
j.Dropoff.State,
j.Pickup.String(),
j.Dropoff.String(),
j.Weight,
j.Miles,
j.Meta,
)
}
out := ""
clients := config.Get().Clients
for k := range clients {
log.Printf("job multiline: %+v contains %s then use %v", clients[k].States, j.Pickup.State, k)
if strings.Contains(fmt.Sprint(clients[k].States), j.Pickup.State) {
if len(out) > 0 {
out += "\n\n"
}
out += foo(k)
}
}
return out
}