Skip to content

Commit 8214be7

Browse files
authored
[Feature] Added back off if DATA_PLANE URL returns 451
1 parent d4eb956 commit 8214be7

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ _testmain.go
3030

3131
# Artifacts
3232
tmp/*
33+
34+
.vscode

analytics.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ func (c *client) sendAsync(msgs []message, wg *sync.WaitGroup, ex *executor) {
300300
c.errorf("panic - %s", err)
301301
}
302302
}()
303-
c.send(msgs)
303+
c.send(msgs, 0)
304304
}) {
305305
wg.Done()
306306
c.errorf("sending messages failed - %s", ErrTooManyRequests)
@@ -387,7 +387,7 @@ func (c *client) getMarshalled(msgs []message) ([]byte, error) {
387387
}
388388

389389
// Send batch request.
390-
func (c *client) send(msgs []message) {
390+
func (c *client) send(msgs []message, retryAttempt int) {
391391
const attempts = 10
392392

393393
nodePayload := c.getNodePayload(msgs)
@@ -418,9 +418,19 @@ func (c *client) send(msgs []message) {
418418
We would then reset the node count by making a call to configure-info end point, then regenerate the payload at a node level
419419
for only those nodes where we failed in sending the data and then recursively call the send function with the updated payload.
420420
*/
421+
const maxSleepTime = 300 * time.Second
422+
var sleepTimeOut = time.Duration(retryAttempt*5) * time.Second
423+
if sleepTimeOut > maxSleepTime {
424+
sleepTimeOut = maxSleepTime
425+
}
426+
if sleepTimeOut > 0 {
427+
c.debugf("Retrying in %d seconds", int(sleepTimeOut.Seconds()))
428+
time.Sleep(sleepTimeOut)
429+
}
421430
c.setNodeCount()
422431
newMsgs := c.getRevisedMsgs(nodePayload, k)
423-
c.send(newMsgs)
432+
retryAttempt += 1
433+
c.send(newMsgs, retryAttempt)
424434
return
425435
}
426436
if i == attempts-1 {

0 commit comments

Comments
 (0)