locking

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2017 License: Apache-2.0 Imports: 5 Imported by: 12

Documentation

Overview

Package locking handles locking projects when they have in-progress runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	TryLock(lock models.ProjectLock) (bool, models.ProjectLock, error)
	Unlock(project models.Project, workspace string) (*models.ProjectLock, error)
	List() ([]models.ProjectLock, error)
	GetLock(project models.Project, workspace string) (*models.ProjectLock, error)
	UnlockByPull(repoFullName string, pullNum int) ([]models.ProjectLock, error)
}

Backend is an implementation of the locking API we require.

type Client

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

Client is used to perform locking actions.

func NewClient

func NewClient(backend Backend) *Client

NewClient returns a new locking client.

func (*Client) GetLock

func (c *Client) GetLock(key string) (*models.ProjectLock, error)

GetLock attempts to get the lock stored at key. If successful, a pointer to the lock will be returned. Else, the pointer will be nil. An error will only be returned if there was an error getting the lock (i.e. not if there was no lock).

func (*Client) List

func (c *Client) List() (map[string]models.ProjectLock, error)

List returns a map of all locks with their lock key as the map key. The lock key can be used in GetLock() and Unlock().

func (*Client) TryLock

func (c *Client) TryLock(p models.Project, workspace string, pull models.PullRequest, user models.User) (TryLockResponse, error)

TryLock attempts to acquire a lock to a project and workspace.

func (*Client) Unlock

func (c *Client) Unlock(key string) (*models.ProjectLock, error)

Unlock attempts to unlock a project and workspace. If successful, a pointer to the now deleted lock will be returned. Else, that pointer will be nil. An error will only be returned if there was an error deleting the lock (i.e. not if there was no lock).

func (*Client) UnlockByPull

func (c *Client) UnlockByPull(repoFullName string, pullNum int) ([]models.ProjectLock, error)

UnlockByPull deletes all locks associated with that pull request.

type Locker

type Locker interface {
	TryLock(p models.Project, workspace string, pull models.PullRequest, user models.User) (TryLockResponse, error)
	Unlock(key string) (*models.ProjectLock, error)
	List() (map[string]models.ProjectLock, error)
	UnlockByPull(repoFullName string, pullNum int) ([]models.ProjectLock, error)
	GetLock(key string) (*models.ProjectLock, error)
}

type TryLockResponse

type TryLockResponse struct {
	// LockAcquired is true if the lock was acquired from this call.
	LockAcquired bool
	// CurrLock is what project is currently holding the lock.
	CurrLock models.ProjectLock
	// LockKey is an identified by which to lookup and delete this lock.
	LockKey string
}

TryLockResponse results from an attempted lock.

Directories

Path Synopsis
Package boltdb provides a locking implementation using Bolt.
Package boltdb provides a locking implementation using Bolt.

Jump to

Keyboard shortcuts

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