load jobinfo secrets only on demand

master
Bel LaPointe 2022-01-14 08:23:56 -05:00
parent 84217c75e8
commit 8f5ebecee8
2 changed files with 24 additions and 14 deletions

View File

@ -16,6 +16,7 @@ type Job struct {
Weight int Weight int
Miles int Miles int
Meta string Meta string
secrets func() interface{} `json:"-"`
} }
type JobLocation struct { type JobLocation struct {
@ -24,6 +25,18 @@ type JobLocation struct {
State string State string
} }
func (j *Job) Secrets() {
if j.secrets == nil {
return
}
v := j.secrets()
j.secrets = nil
if v == nil {
return
}
j.Meta = fmt.Sprintf("%s %+v", j.Meta, v)
}
func (j Job) String() string { func (j Job) String() string {
return fmt.Sprintf( return fmt.Sprintf(
`%s => %s (%d miles), Weight:%d, Notes:%s Link:%s`, `%s => %s (%d miles), Weight:%d, Notes:%s Link:%s`,

View File

@ -88,18 +88,7 @@ func (ntgJob *ntgVisionJob) jobInfo() (ntgVisionJobInfo, error) {
return result, err return result, err
} }
func (ntgJob *ntgVisionJob) Job(info ...bool) Job { func (ntgJob *ntgVisionJob) Job() Job {
if len(info) == 0 || !info[0] {
return ntgJob.job(ntgVisionJobInfo{})
}
jobInfo, err := ntgJob.JobInfo()
if err != nil {
log.Printf("failed to get jobinfo: %v", err)
}
return ntgJob.job(jobInfo)
}
func (ntgJob *ntgVisionJob) job(jobInfo ntgVisionJobInfo) Job {
pickup, _ := time.ParseInLocation("01/02/06", ntgJob.PickupDate, time.Local) pickup, _ := time.ParseInLocation("01/02/06", ntgJob.PickupDate, time.Local)
dropoff, _ := time.ParseInLocation("01/02/06", ntgJob.DropoffDate, time.Local) dropoff, _ := time.ParseInLocation("01/02/06", ntgJob.DropoffDate, time.Local)
return Job{ return Job{
@ -117,7 +106,15 @@ func (ntgJob *ntgVisionJob) job(jobInfo ntgVisionJobInfo) Job {
}, },
Miles: ntgJob.Miles, Miles: ntgJob.Miles,
Weight: ntgJob.Weight, Weight: ntgJob.Weight,
Meta: fmt.Sprintf("equipment:%s, secrets:%+v", ntgJob.Equipment, jobInfo), Meta: fmt.Sprintf("equipment:%s", ntgJob.Equipment),
secrets: func() interface{} {
jobInfo, err := ntgJob.JobInfo()
if err != nil {
log.Printf("failed to get jobinfo: %v", err)
return nil
}
return jobInfo
},
} }
} }
@ -151,7 +148,7 @@ func (ntg NTGVision) Search(states []config.State) ([]Job, error) {
jobs := make([]Job, len(ntgjobs)) jobs := make([]Job, len(ntgjobs))
for i := range jobs { for i := range jobs {
jobs[i] = ntgjobs[i].Job(true) jobs[i] = ntgjobs[i].Job()
} }
return jobs, err return jobs, err
} }