Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc2efe928a | ||
|
|
e1b4460ebd | ||
|
|
9bb9929ff6 | ||
|
|
a6c1b8505a | ||
|
|
c755aa88fb | ||
|
|
b451ed93bf | ||
|
|
76b7211d6c | ||
|
|
31a608d7f8 |
@@ -93,7 +93,7 @@ func (ntgJob *ntgVisionJob) JobInfo() (ntgVisionJobInfo, error) {
|
|||||||
key := fmt.Sprintf("ntg_job_info_%v", ntgJob.ID)
|
key := fmt.Sprintf("ntg_job_info_%v", ntgJob.ID)
|
||||||
if b, err := db.Get(key); err != nil {
|
if b, err := db.Get(key); err != nil {
|
||||||
} else if err := json.Unmarshal(b, &ntgJob.jobinfo); 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()
|
ntg := NewNTGVision()
|
||||||
ji, err := ntg.SearchJob(ntgJob.ID)
|
ji, err := ntg.SearchJob(ntgJob.ID)
|
||||||
@@ -228,12 +228,14 @@ func setNTGToken(token string) {
|
|||||||
|
|
||||||
func (ntg NTGVision) search(states []config.State) (io.ReadCloser, error) {
|
func (ntg NTGVision) search(states []config.State) (io.ReadCloser, error) {
|
||||||
if getNTGToken() == "" {
|
if getNTGToken() == "" {
|
||||||
|
logtr.Debugf("NTG token is empty, refreshing ntg auth")
|
||||||
if err := ntg.refreshAuth(); err != nil {
|
if err := ntg.refreshAuth(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rc, err := ntg._search(states)
|
rc, err := ntg._search(states)
|
||||||
if err == ErrNoAuth {
|
if err == ErrNoAuth {
|
||||||
|
logtr.Debugf("err no auth on search, refreshing ntg auth")
|
||||||
if err := ntg.refreshAuth(); err != nil {
|
if err := ntg.refreshAuth(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -295,7 +297,9 @@ func (ntg NTGVision) _search(states []config.State) (io.ReadCloser, error) {
|
|||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
b, _ := ioutil.ReadAll(resp.Body)
|
b, _ := ioutil.ReadAll(resp.Body)
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
if resp.StatusCode > 400 && resp.StatusCode < 500 && resp.StatusCode != 404 && resp.StatusCode != 410 {
|
logtr.Warnf("ntg auth bad status: url=%s, status=%v, body=%s", request.URL.String(), resp.StatusCode, b)
|
||||||
|
if resp.StatusCode > 400 && resp.StatusCode < 404 {
|
||||||
|
logtr.Warnf("ntg auth bad status: err no auth")
|
||||||
return nil, ErrNoAuth
|
return nil, ErrNoAuth
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("bad status searching ntg: %d: %s", resp.StatusCode, b)
|
return nil, fmt.Errorf("bad status searching ntg: %d: %s", resp.StatusCode, b)
|
||||||
@@ -305,7 +309,7 @@ func (ntg NTGVision) _search(states []config.State) (io.ReadCloser, error) {
|
|||||||
|
|
||||||
func (ntg NTGVision) newRequest(states []config.State) (*http.Request, error) {
|
func (ntg NTGVision) newRequest(states []config.State) (*http.Request, error) {
|
||||||
body, err := json.Marshal(map[string]interface{}{
|
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"),
|
"OriginToDate": time.Now().UTC().Add(time.Hour * 24 * 30).Format("2006-01-02T15:04:05.000Z"),
|
||||||
"DestinationFromDate": nil,
|
"DestinationFromDate": nil,
|
||||||
"DestinationToDate": nil,
|
"DestinationToDate": nil,
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ func SetLevel(l Level) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func logf(l Level, format string, args []interface{}) {
|
func logf(l Level, format string, args []interface{}) {
|
||||||
format = fmt.Sprintf("%v: %v: %s\n", time.Now().Format("15:04:05"), l.String(), strings.TrimSpace(format))
|
format = fmt.Sprintf("%v: %v: %s\n", time.Now().Format("01-02T15:04:05"), l.String(), strings.TrimSpace(format))
|
||||||
cLevel := level
|
cLevel := level
|
||||||
cAnsoser := ansoser
|
cAnsoser := ansoser
|
||||||
if l >= cLevel {
|
if l >= cLevel {
|
||||||
|
|||||||
5
main.go
5
main.go
@@ -350,9 +350,14 @@ func updateDeadJobs(jobs []broker.Job) error {
|
|||||||
if err := json.Unmarshal(b, &recorded); err != nil {
|
if err := json.Unmarshal(b, &recorded); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
/* // TODO this beeps on fluffychat
|
||||||
if err := message.NewMatrix().Update(recorded.MatrixID, recorded.Job.FormatMultilineTextDead()); err != nil {
|
if err := message.NewMatrix().Update(recorded.MatrixID, recorded.Job.FormatMultilineTextDead()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
if err := message.NewMatrix().Remove(recorded.MatrixID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if err := db.Set(listEntry, nil); err != nil {
|
if err := db.Set(listEntry, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
todo:
|
todo:
|
||||||
|
- !states emits current state
|
||||||
- TEST. Just like, refactor and test to shit.
|
- TEST. Just like, refactor and test to shit.
|
||||||
- try search ntg by autoinc?
|
- try search ntg by autoinc?
|
||||||
- test each !command callbacks to matrix
|
- test each !command callbacks to matrix
|
||||||
|
|||||||
Reference in New Issue
Block a user