lock

package
v0.136.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func LockStackContext(ctx context.Context, stackKey, holder string) error

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

func StackKey(contextName, stackName string) string

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

func StackLockHolder(stackKey string) (string, bool)

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

func TryLockStack(stackKey, holder string) (bool, string)

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

func GetRepoLock(repoName string) *RepoLock

GetRepoLock retrieves or creates a RepoLock for the given repoName.

func (*RepoLock) Holder

func (l *RepoLock) Holder() string

Holder returns the jobID of the current lock holder.

func (*RepoLock) Lock

func (l *RepoLock) Lock()

Lock acquires the lock, blocking until it is available.

func (*RepoLock) LockContext added in v0.114.0

func (l *RepoLock) LockContext(ctx context.Context, jobID string) bool

LockContext acquires the lock in waiter order or returns false when ctx is cancelled.

func (*RepoLock) TryLock

func (l *RepoLock) TryLock(jobID string) bool

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

type StackBusyError struct {
	Key    string
	Holder string
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL