Documentation
¶
Index ¶
- Variables
- func AcquireStack(ctx context.Context, stackKey string, opts AcquireStackOptions) (func(), error)
- func LockStack(stackName string)
- func LockStackContext(ctx context.Context, stackKey, holder string) error
- func StackKey(contextName, stackName string) string
- func StackLockHolder(stackKey string) (string, bool)
- func TryLockStack(stackKey, holder string) (bool, string)
- func UnlockStack(stackName string)
- type AcquireStackOptions
- type RepoLock
- type StackBusyError
Constants ¶
This section is empty.
Variables ¶
var ErrStackBusy = errors.New("stack is locked by another operation")
ErrStackBusy reports that a stack lock is held by another operation and the caller chose not to wait for it.
Functions ¶
func AcquireStack ¶ added in v0.136.0
func AcquireStack(ctx context.Context, stackKey string, opts AcquireStackOptions) (func(), error)
AcquireStack acquires the per-stack lock for stackKey and returns a function that releases it. A busy lock either returns a *StackBusyError (which matches ErrStackBusy) or waits until ctx ends, based on opts.Wait. If stackKey is empty the call is a no-op.
func LockStack ¶ added in v0.89.2
func LockStack(stackName string)
LockStack acquires the per-stack scheduler/deployment lock for stackName. While held, scheduled runs and deployments for this specific stack are mutually exclusive. Different stacks do not block each other. It blocks without a bound. Prefer LockStackContext, which can stop waiting. If stackName is empty the call is a no-op.
func LockStackContext ¶ added in v0.136.0
LockStackContext acquires the per-stack lock for stackKey and records holder as the description of the operation that holds it. It returns the context error when ctx ends before the lock is free. If stackKey is empty the call is a no-op.
func StackKey ¶ added in v0.113.0
StackKey builds the per-stack lock key for a stack deployed to a Docker context. Stack names are only unique within a Docker context, so same-named stacks on different contexts must not block each other. The default context keeps the bare stack name so callers that only ever operate on it (the job scheduler and the certificate rotation watcher) stay mutually exclusive with its deployments.
func StackLockHolder ¶ added in v0.136.0
StackLockHolder returns the description of the operation that holds the per-stack lock for stackKey, and whether the lock is held.
func TryLockStack ¶ added in v0.136.0
TryLockStack acquires the per-stack lock for stackKey only when it is free. When the lock is busy, it returns false and the description of the holder. If stackKey is empty the call is a no-op and returns true.
func UnlockStack ¶ added in v0.89.2
func UnlockStack(stackName string)
UnlockStack releases the per-stack scheduler/deployment lock for stackName. If stackName is empty the call is a no-op.
Types ¶
type AcquireStackOptions ¶ added in v0.136.0
type AcquireStackOptions struct {
// Holder describes the operation that acquires the lock.
Holder string
// Wait makes AcquireStack wait for a busy lock until ctx ends.
// Without Wait, a busy lock returns a *StackBusyError at once.
Wait bool
// OnWait is called once with the current holder before AcquireStack
// starts to wait for a busy lock.
OnWait func(holder string)
}
AcquireStackOptions controls how AcquireStack acquires a stack lock.
type RepoLock ¶
type RepoLock struct {
// contains filtered or unexported fields
}
RepoLock represents a lock for a specific repository.
func GetRepoLock ¶
GetRepoLock retrieves or creates a RepoLock for the given repoName.
func (*RepoLock) Lock ¶
func (l *RepoLock) Lock()
Lock acquires the lock, blocking until it is available.
func (*RepoLock) LockContext ¶ added in v0.114.0
LockContext acquires the lock in waiter order or returns false when ctx is cancelled.
func (*RepoLock) TryLock ¶
TryLock attempts to acquire the lock for the given jobID. It returns true if the lock was successfully acquired.
func (*RepoLock) Unlock ¶
func (l *RepoLock) Unlock()
Unlock releases the lock and hands it to the next queued waiter, if any. It panics when the lock is not held, mirroring sync.Mutex misuse semantics: a stray Unlock would otherwise silently grant the lock to a waiter while the real holder is still running.
type StackBusyError ¶ added in v0.136.0
StackBusyError tells which operation holds a busy stack lock.
func (*StackBusyError) Error ¶ added in v0.136.0
func (e *StackBusyError) Error() string
func (*StackBusyError) Unwrap ¶ added in v0.136.0
func (e *StackBusyError) Unwrap() error
Unwrap lets errors.Is match ErrStackBusy.