Drill

ProblemsGo › payments

Should this call be retried

mediumpaymentsMathGo

The gateway client decides whether a failed call is worth trying again, or whether retrying would only make things worse.

shouldRetry(status: int, attempt: int) → bool

Go needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.

Solve it in Python →

Where you start

func shouldRetry(status int, attempt int) bool {
	
}

Worked examples

CallResult
shouldRetry(500, 1)true
shouldRetry(429, 2)true
shouldRetry(503, 3)false
shouldRetry(404, 1)false

Hint

Deal with the attempt ceiling first, then the status.

Reference solution in Go
func shouldRetry(status int, attempt int) bool {
	if attempt < 1 || attempt >= 3 {
		return false
	}
	return status == 429 || (status >= 500 && status <= 599)
}

The same problem in another language

More payments problems in Go