Skip to content

Commit

Permalink
adjust output
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlindhe committed Apr 22, 2021
1 parent cf6a471 commit 2f2b6a1
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions pkg/csender/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ func (cs *Csender) GracefulSend() error {

for {
statusCode, err := cs.Send()
if err == nil {
return nil
}

if cs.Verbose {
if statusCode >= 200 && statusCode <= 299 {
fmt.Fprintln(os.Stdout, "HTTP CODE", statusCode)
Expand All @@ -63,28 +59,29 @@ func (cs *Csender) GracefulSend() error {
}
}

if err == nil {
return nil
}

if err == cagent.ErrHubTooManyRequests {
// for error code 429, wait 10 seconds and try again
retryIn = 10 * time.Second
log.Infof("csender: HTTP 429, too many requests, retrying in %v", retryIn)
if cs.Verbose {
fmt.Fprintf(os.Stdout, "got HTTP %d from %s, retrying in %v\n", statusCode, cs.HubURL, retryIn)
log.Infof("got HTTP %d from %s, retrying in %v", statusCode, cs.HubURL, retryIn)
}
} else if err == cagent.ErrHubServerError || errors.Is(err, context.DeadlineExceeded) {
// for error codes 5xx, wait for 1 seconds and try again, increase by 1 second each retry
retries++
retryIn = time.Duration(retries) * time.Second

if retries > cs.RetryLimit {
log.Errorf("csender: hub connection error, giving up after %d tries", retries)
if cs.Verbose {
fmt.Fprintf(os.Stderr, "giving up after %d tries\n", retries)
fmt.Fprintf(os.Stderr, "hub connection error, giving up after %d retries\n", retries-1)
}
return nil
}
log.Infof("csender: hub connection error '%s', %d/%d, retrying in %v", err, retries, cs.RetryLimit, retryIn)
if cs.Verbose {
fmt.Fprintf(os.Stdout, "got HTTP %d from %s, retrying in %v\n", statusCode, cs.HubURL, retryIn)
fmt.Fprintf(os.Stdout, "hub connection error '%s', got HTTP %d from %s, retrying in %v\n", err, statusCode, cs.HubURL, retryIn)
}
} else {
return err
Expand Down

0 comments on commit 2f2b6a1

Please sign in to comment.