Skip to content

Commit

Permalink
Simplified Repeat Request Methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhgmailcom committed Dec 4, 2024
1 parent 05a39bd commit bcdde89
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions vehicle/saic/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewAPI(log *util.Logger, identity *Identity) *API {
return v
}

func (v *API) doRepeatedRequest(baseUrl string, path string, event_id string) error {
func (v *API) doRepeatedRequest(path string, event_id string) error {
var req *http.Request

answer := requests.Answer{
Expand All @@ -69,7 +69,7 @@ func (v *API) doRepeatedRequest(baseUrl string, path string, event_id string) er
}

req, err = requests.CreateRequest(
baseUrl,
v.identity.baseUrl,
path,
http.MethodGet,
"",
Expand All @@ -91,15 +91,15 @@ func (v *API) doRepeatedRequest(baseUrl string, path string, event_id string) er
}

// This is running concurrently
func (v *API) repeatRequest(baseUrl string, path string, event_id string) {
func (v *API) repeatRequest(path string, event_id string) {
var err error
var count int

v.request.Status = StatRunning
for err = api.ErrMustRetry; err == api.ErrMustRetry && count < 20; {
time.Sleep(2 * time.Second)
v.Logger.DEBUG.Printf("Starting repeated query. Count: %d\n", count)
err = v.doRepeatedRequest(baseUrl, path, event_id)
err = v.doRepeatedRequest(path, event_id)
count++
}

Expand Down Expand Up @@ -252,7 +252,7 @@ func (v *API) Status(vin string) (requests.ChargeStatus, error) {
if err == api.ErrMustRetry {
v.request.Status = StatRunning
v.Logger.DEBUG.Printf(" No answer yet. Continue status query in background\n")
go v.repeatRequest(v.identity.baseUrl, path, event_id)
go v.repeatRequest(path, event_id)
} else if err != nil {
v.Logger.ERROR.Printf("doRequest failed with %s", err.Error())
}
Expand Down

0 comments on commit bcdde89

Please sign in to comment.