(timeout time.Duration, maxRetries int)
| 18 | const defaultMaxLockRetries = 12 |
| 19 | |
| 20 | func execLockRetry(timeout time.Duration, maxRetries int) dbx.ExecHookFunc { |
| 21 | return func(q *dbx.Query, op func() error) error { |
| 22 | if q.Context() == nil { |
| 23 | cancelCtx, cancel := context.WithTimeout(context.Background(), timeout) |
| 24 | defer func() { |
| 25 | cancel() |
| 26 | //nolint:staticcheck |
| 27 | q.WithContext(nil) // reset |
| 28 | }() |
| 29 | q.WithContext(cancelCtx) |
| 30 | } |
| 31 | |
| 32 | execErr := baseLockRetry(func(attempt int) error { |
| 33 | return op() |
| 34 | }, maxRetries) |
| 35 | if execErr != nil && !errors.Is(execErr, sql.ErrNoRows) { |
| 36 | execErr = fmt.Errorf("%w; failed query: %s", execErr, q.SQL()) |
| 37 | } |
| 38 | |
| 39 | return execErr |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | func baseLockRetry(op func(attempt int) error, maxRetries int) error { |
| 44 | attempt := 1 |
no test coverage detected
searching dependent graphs…