Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6c1b8505a | ||
|
|
c755aa88fb | ||
|
|
b451ed93bf | ||
|
|
76b7211d6c | ||
|
|
31a608d7f8 | ||
|
|
0c3419a1fb |
@@ -1,6 +1,7 @@
|
||||
package broker
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"local/truckstop/config"
|
||||
"local/truckstop/logtr"
|
||||
@@ -26,6 +27,18 @@ type JobLocation struct {
|
||||
State string
|
||||
}
|
||||
|
||||
func (j Job) UID() string {
|
||||
return fmt.Sprintf(
|
||||
"%v-%s-%s-%s-%s-%v",
|
||||
j.ID,
|
||||
j.Pickup.State,
|
||||
base64.StdEncoding.EncodeToString([]byte(j.Pickup.City)),
|
||||
j.Dropoff.State,
|
||||
base64.StdEncoding.EncodeToString([]byte(j.Dropoff.City)),
|
||||
j.Pickup.Date.Unix(),
|
||||
)
|
||||
}
|
||||
|
||||
func (j *Job) Secrets() {
|
||||
if j.secrets == nil {
|
||||
return
|
||||
|
||||
@@ -93,7 +93,7 @@ func (ntgJob *ntgVisionJob) JobInfo() (ntgVisionJobInfo, error) {
|
||||
key := fmt.Sprintf("ntg_job_info_%v", ntgJob.ID)
|
||||
if b, err := db.Get(key); err != nil {
|
||||
} else if err := json.Unmarshal(b, &ntgJob.jobinfo); err == nil {
|
||||
return ntgJob.jobinfo, fmt.Errorf("failed to parse ntg job info from db: %w: %s", err, b)
|
||||
return ntgJob.jobinfo, nil
|
||||
}
|
||||
ntg := NewNTGVision()
|
||||
ji, err := ntg.SearchJob(ntgJob.ID)
|
||||
@@ -305,7 +305,7 @@ func (ntg NTGVision) _search(states []config.State) (io.ReadCloser, error) {
|
||||
|
||||
func (ntg NTGVision) newRequest(states []config.State) (*http.Request, error) {
|
||||
body, err := json.Marshal(map[string]interface{}{
|
||||
"OriginFromDate": time.Now().UTC().Format("2006-01-02T15:04:05.000Z"),
|
||||
"OriginFromDate": time.Now().Add(time.Hour * -24).UTC().Format("2006-01-02T15:04:05.000Z"),
|
||||
"OriginToDate": time.Now().UTC().Add(time.Hour * 24 * 30).Format("2006-01-02T15:04:05.000Z"),
|
||||
"DestinationFromDate": nil,
|
||||
"DestinationToDate": nil,
|
||||
|
||||
7
main.go
7
main.go
@@ -291,12 +291,13 @@ func once() error {
|
||||
jobs[i].Secrets()
|
||||
}
|
||||
logtr.Infof("once: sending jobs: %+v", jobs)
|
||||
db := config.Get().DB()
|
||||
for i := range jobs {
|
||||
if ok, err := sendJob(jobs[i]); err != nil {
|
||||
return err
|
||||
} else if ok {
|
||||
logtr.Debugf("sent job", jobs[i])
|
||||
if err := config.Get().DB().Set(jobs[i].ID, []byte(`sent`)); err != nil {
|
||||
if err := db.Set(jobs[i].UID(), []byte(`sent`)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -349,9 +350,11 @@ func updateDeadJobs(jobs []broker.Job) error {
|
||||
if err := json.Unmarshal(b, &recorded); err != nil {
|
||||
return err
|
||||
}
|
||||
/* // TODO this beeps on fluffychat
|
||||
if err := message.NewMatrix().Update(recorded.MatrixID, recorded.Job.FormatMultilineTextDead()); err != nil {
|
||||
return err
|
||||
}
|
||||
*/
|
||||
if err := db.Set(listEntry, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -368,7 +371,7 @@ func updateDeadJobs(jobs []broker.Job) error {
|
||||
func dropStaleJobs(jobs []broker.Job) ([]broker.Job, error) {
|
||||
db := config.Get().DB()
|
||||
for i := len(jobs) - 1; i >= 0; i-- {
|
||||
if _, err := db.Get(jobs[i].ID); err == storage.ErrNotFound {
|
||||
if _, err := db.Get(jobs[i].UID()); err == storage.ErrNotFound {
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user