Back to / core / machinelock

Package machinelock

Latest Go to latest

The latest major version is .

Published: Sep 21, 2020 | License: AGPL-3.0 | Module:



const Filename = "machine-lock.log"

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

func New

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

New creates a new machine lock.

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

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

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.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier