MCPcopy
hub / github.com/pocketbase/pocketbase / execLockRetry

Function execLockRetry

core/db_retry.go:20–41  ·  view source on GitHub ↗
(timeout time.Duration, maxRetries int)

Source from the content-addressed store, hash-verified

18const defaultMaxLockRetries = 12
19
20func 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
43func baseLockRetry(op func(attempt int) error, maxRetries int) error {
44 attempt := 1

Callers 2

RecordQueryMethod · 0.85
modelQueryMethod · 0.85

Calls 4

baseLockRetryFunction · 0.85
opFunction · 0.85
IsMethod · 0.80
ContextMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…