Documentation
¶
Overview ¶
Package lockfile provides cross-process file locks using lease heartbeats and stale-lock reclamation semantics for command and daemon orchestration.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrLockHeld = errors.New("lock file is already held by another process")
ErrLockHeld reports that another process currently owns the lock file.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// HeldError is wrapped when an active owner is detected.
// Defaults to ErrLockHeld when unset.
HeldError error
// AcquireRetryLimit is the number of retry attempts after a stale-lock remove
// race before giving up.
AcquireRetryLimit int
// AcquireRetryDelay is the delay between lock acquisition retries.
AcquireRetryDelay time.Duration
// InvalidPIDLockStaleThreshold is the age threshold before reclaiming lock
// files that do not contain a parseable lease record.
InvalidPIDLockStaleThreshold time.Duration
// FileWriteMode is used when creating lock files.
FileWriteMode fs.FileMode
// DirectoryWriteMode is used when creating parent directories.
DirectoryWriteMode fs.FileMode
// ProcessAppearsAlive is ignored and retained only for API stability.
ProcessAppearsAlive func(processID int) bool
// LeaseHeartbeatInterval controls heartbeat write cadence while lock is held.
// Defaults to 250ms when unset.
LeaseHeartbeatInterval time.Duration
// LeaseStaleThreshold is the stale lease threshold before takeover.
// Defaults to 3s when unset.
LeaseStaleThreshold time.Duration
// OnLeaseLost is called when ownership is lost while the lock is held.
OnLeaseLost func()
}
Options controls lock-file behavior.
type PIDLock ¶
type PIDLock struct {
// contains filtered or unexported fields
}
PIDLock manages exclusive ownership for one lock-file path using lease files.
func NewPIDLock ¶
NewPIDLock creates a lock using default lock options.
func NewPIDLockWithOptions ¶
NewPIDLockWithOptions creates a lock with explicit options.
Click to show internal directories.
Click to hide internal directories.