lockfile

package
v0.85.0-pre.7 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

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
	// 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

func NewPIDLock(lock_file_path string) *PIDLock

NewPIDLock creates a lock using default lock options.

func NewPIDLockWithOptions

func NewPIDLockWithOptions(lock_file_path string, options Options) *PIDLock

NewPIDLockWithOptions creates a lock with explicit options.

func (*PIDLock) Acquire

func (lock *PIDLock) Acquire() error

Acquire obtains lock ownership or returns a held error.

func (*PIDLock) Held

func (lock *PIDLock) Held() bool

Held reports whether Acquire has succeeded in-process and has not been released.

func (*PIDLock) Path

func (lock *PIDLock) Path() string

Path returns the full lock-file path.

func (*PIDLock) Release

func (lock *PIDLock) Release() error

Release drops lock ownership by removing the lock file.

Jump to

Keyboard shortcuts

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