lock

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLocked when locking an key that is already locked.
	ErrLocked = errors.New("key is locked")
)

Functions

This section is empty.

Types

type Client added in v1.0.0

type Client struct {
	// contains filtered or unexported fields
}

Client holds lock configuration.

func New added in v1.0.0

func New(ddb storageI, table string) *Client

New creates a new lock client.

func NewTestClient added in v1.0.0

func NewTestClient(t *testing.T) *Client

NewTestClient returns a test client with in-memory storage that can be used for lock testing.

func (*Client) Lock added in v1.0.0

func (c *Client) Lock(ctx context.Context, key string, expire time.Duration) error

Lock creates a new lock with "key" as a unique identifier. The lock will expire after the specified duration. Returns ErrLocked if the lock already exists and has not expired.

func (*Client) Locked added in v1.0.0

func (c *Client) Locked(ctx context.Context, key string) (bool, error)

Locked checks if the current key is locked.

func (*Client) Run added in v1.0.0

func (c *Client) Run(ctx context.Context, key, command string) (string, error)

Run acquires a lock under the specified key, executes the command, and then unlocks the key. Returns ErrLocked if the key is already locked. Otherwise returns combined stdout and stderr of the command and the command error. If the unlock step fails the lock expires after 24 hours.

func (*Client) Unlock added in v1.0.0

func (c *Client) Unlock(ctx context.Context, key string) error

Unlock releases an existing lock of the specified key. Does not error if the lock doesn't exist.

Jump to

Keyboard shortcuts

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