(op func(attempt int) error, maxRetries int)
| 41 | } |
| 42 | |
| 43 | func baseLockRetry(op func(attempt int) error, maxRetries int) error { |
| 44 | attempt := 1 |
| 45 | |
| 46 | Retry: |
| 47 | err := op(attempt) |
| 48 | |
| 49 | if err != nil && attempt <= maxRetries { |
| 50 | errStr := err.Error() |
| 51 | // we are checking the error against the plain error texts since the codes could vary between drivers |
| 52 | if strings.Contains(errStr, "database is locked") || |
| 53 | strings.Contains(errStr, "table is locked") { |
| 54 | // wait and retry |
| 55 | time.Sleep(getDefaultRetryInterval(attempt)) |
| 56 | attempt++ |
| 57 | goto Retry |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | return err |
| 62 | } |
| 63 | |
| 64 | func getDefaultRetryInterval(attempt int) time.Duration { |
| 65 | if attempt < 0 || attempt > len(defaultRetryIntervals)-1 { |
searching dependent graphs…