machinelock

package
v0.0.0-...-298751d Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: AGPL-3.0 Imports: 11 Imported by: 12

Documentation

Index

Constants

View Source
const Filename = "machine-lock.log"

Filename represents the name of the logfile that is created in the LOG_DIR.

Variables

This section is empty.

Functions

func New

func New(config Config) (*lock, error)

New creates a new machine lock.

Types

type Clock

type Clock interface {
	// After waits for the duration to elapse and then sends the
	// current time on the returned channel.
	After(time.Duration) <-chan time.Time

	// Now returns the current clock time.
	Now() time.Time
}

Clock provides an interface for dealing with clocks.

type Config

type Config struct {
	AgentName   string
	Clock       Clock
	Logger      Logger
	LogFilename string
}

Config defines the attributes needed to correctly construct a machine lock.

func (Config) Validate

func (c Config) Validate() error

Validate ensures that all the required config values are set.

type Lock

type Lock interface {
	Acquire(spec Spec) (func(), error)
	Report(opts ...ReportOption) (string, error)
}

Lock is used to give external packages something to refer to.

type Logger

type Logger interface {
	Debugf(string, ...interface{})
	Warningf(string, ...interface{})
}

Logger defines the logging methods used by the machine lock.

type ReportOption

type ReportOption int
const (
	ShowHistory ReportOption = iota
	ShowStack
	ShowDetailsYAML
)

type Spec

type Spec struct {
	Cancel <-chan struct{}
	// The purpose of the NoCancel is to ensure that there isn't
	// an accidental forgetting of the cancel channel. The primary
	// use case for this is the reboot worker that doesn't want to
	// pass in a cancel channel because it really wants to reboot.
	NoCancel bool
	Worker   string
	Comment  string
	Group    string
}

Spec is an argument struct for the `Acquire` method. It must have a Cancel channel and a Worker name defined.

func (Spec) Validate

func (s Spec) Validate() error

Validate ensures that a Cancel channel and a Worker name are defined.

Jump to

Keyboard shortcuts

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