locks

package
v0.0.0-...-305ec12 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2015 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deferral

type Deferral struct {
	// The underlying opaque build event.
	Data string `json:"-"`
	// The key under which the deferred build is stored.
	Key string `json:"key"`
}

Deferral models a deferred build. Data is the serialized build event, while key is the identifier assigned to this deferred build by the locker service.

type EtcdLocker

type EtcdLocker struct {
	// Config is the underlying etcd cluster configuration
	Config etcd.Config
}

EtcdLocker is the Locker implementation on top of etcd.

func (EtcdLocker) ClearDeferred

func (d EtcdLocker) ClearDeferred(deferralID string) (*etcd.Response, error)

ClearDeferred removes a build from the deferred list.

func (EtcdLocker) Defer

func (d EtcdLocker) Defer(buildEvent []byte) (*etcd.Response, error)

Defer defers a build by saving it to a locker service provided key. See Atomically Creating In-Order Keys at https://coreos.com/etcd/docs/0.4.7/etcd-api/.

func (EtcdLocker) DeferredBuilds

func (d EtcdLocker) DeferredBuilds() ([]Deferral, error)

DeferredBuilds returns the list of builds currently deferred.

func (EtcdLocker) InitDeferred

func (d EtcdLocker) InitDeferred() error

InitDeferred creates the directory in etcd where deferred builds are stored.

func (EtcdLocker) Key

func (d EtcdLocker) Key(projectKey, branch string) string

Key defines an unique, opaque key that locks a build.

func (EtcdLocker) Lock

func (d EtcdLocker) Lock(key, value string) (*etcd.Response, error)

Lock locks a build on top of etcd.

func (EtcdLocker) Unlock

func (d EtcdLocker) Unlock(key, value string) (*etcd.Response, error)

Unlock unlocks a build on top of etcd.

type Locker

type Locker interface {
	// Lock sets a lock in the lock service to prevent concurrent builds of a given branch
	Lock(key, value string) (*etcd.Response, error)
	// Unlock clears a lock on a build
	Unlock(key, value string) (*etcd.Response, error)
	// Defer creates an entry in the lock service that marks a build as deferred.
	Defer(buildEvent []byte) (*etcd.Response, error)
	// Clears the entry for a deferred build
	ClearDeferred(deferredID string) (*etcd.Response, error)
	// Returns the current list of deferred builds in created order
	DeferredBuilds() ([]Deferral, error)
	// Initialize the deferred build system if necessary
	InitDeferred() error
	// Form the opaque key for a given branch on a project
	Key(projectKey, branch string) string
}

Locker defines the interface the build locker and build deferral instance makes available.

func NewEtcdLocker

func NewEtcdLocker(machines []string) Locker

New returns a new etcd implementation of a Locker.

type NoOpLocker

type NoOpLocker struct {
	Data      []byte
	Error     error
	Deferrals []Deferral
}

func (*NoOpLocker) ClearDeferred

func (noop *NoOpLocker) ClearDeferred(deferralID string) (*etcd.Response, error)

func (*NoOpLocker) Defer

func (noop *NoOpLocker) Defer(data []byte) (*etcd.Response, error)

func (*NoOpLocker) DeferredBuilds

func (noop *NoOpLocker) DeferredBuilds() ([]Deferral, error)

func (*NoOpLocker) InitDeferred

func (noop *NoOpLocker) InitDeferred() error

func (*NoOpLocker) Key

func (noop *NoOpLocker) Key(projectKey, branch string) string

func (*NoOpLocker) Lock

func (noop *NoOpLocker) Lock(key, value string) (*etcd.Response, error)

func (*NoOpLocker) Unlock

func (noop *NoOpLocker) Unlock(key, value string) (*etcd.Response, error)

Jump to

Keyboard shortcuts

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