Documentation
¶
Index ¶
- Variables
- func RefreshWithRetry(ctx context.Context, pool LockExecutor, integrationID uuid.UUID, ...) error
- func RefreshWithRetryFn(ctx context.Context, pool LockExecutor, integrationID uuid.UUID, ...) error
- func RegisterMetrics(_ interface{})
- func WithRefreshLock(ctx context.Context, pool LockExecutor, integrationID uuid.UUID, ...) error
- type LockExecutor
Constants ¶
This section is empty.
Variables ¶
var ( // ErrLockBusy is returned when pg_try_advisory_xact_lock returns false — // another transaction holds the lock for this integration. ErrLockBusy = errors.New("oauthlock: lock busy") // ErrLockExhausted is returned by RefreshWithRetry when all backoff // attempts are exhausted without acquiring the lock. ErrLockExhausted = errors.New("oauthlock: retries exhausted") )
var ContendedTotal = promauto.NewCounterVec(prometheus.CounterOpts{ Name: "oauth_refresh_lock_contended_total", Help: "OAuth refresh attempts that failed to acquire the advisory lock and returned ErrLockBusy.", }, []string{"platform"})
ContendedTotal counts OAuth refresh attempts that failed to acquire the advisory lock and returned ErrLockBusy.
var ExhaustedTotal = promauto.NewCounterVec(prometheus.CounterOpts{ Name: "oauth_refresh_lock_exhausted_total", Help: "OAuth refresh attempts that exhausted all backoff retries without acquiring the advisory lock.", }, []string{"platform"})
ExhaustedTotal counts OAuth refresh attempts that exhausted all backoff retries without acquiring the advisory lock.
Functions ¶
func RefreshWithRetry ¶
func RefreshWithRetry( ctx context.Context, pool LockExecutor, integrationID uuid.UUID, platform string, fn func(context.Context, pgx.Tx) error, ) error
RefreshWithRetry retries WithRefreshLock with exponential backoff on ErrLockBusy. Returns ErrLockExhausted after all slots are exhausted.
func RefreshWithRetryFn ¶
func RefreshWithRetryFn( ctx context.Context, pool LockExecutor, integrationID uuid.UUID, platform string, fn func(context.Context, pgx.Tx) error, lockFn func(context.Context, LockExecutor, uuid.UUID, string, func(context.Context, pgx.Tx) error) error, ) error
RefreshWithRetryFn is RefreshWithRetry with an injectable lock function for testing. Production callers should use RefreshWithRetry.
func RegisterMetrics ¶
func RegisterMetrics(_ interface{})
RegisterMetrics is a no-op for the promauto-registered counters; it exists so tests can call it to verify the package is importable.
func WithRefreshLock ¶
func WithRefreshLock( ctx context.Context, pool LockExecutor, integrationID uuid.UUID, platform string, fn func(context.Context, pgx.Tx) error, ) error
WithRefreshLock opens a transaction, tries to acquire pg_try_advisory_xact_lock keyed by integrationID, and calls fn inside the transaction. The lock is released automatically on commit or rollback. Returns ErrLockBusy immediately when the lock is held by another connection.