Documentation ¶
Overview ¶
Copyright 2017 HootSuite Media Inc.
Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Modified hereafter by contributors to runatlantis/atlantis.
Package locking handles locking projects when they have in-progress runs.
Index ¶
- type ApplyClient
- type ApplyCommandLock
- type ApplyLockChecker
- type ApplyLocker
- type Backend
- type Client
- func (c *Client) GetLock(key string) (*models.ProjectLock, error)
- func (c *Client) List() (map[string]models.ProjectLock, error)
- func (c *Client) TryLock(p models.Project, workspace string, pull models.PullRequest, user models.User) (TryLockResponse, error)
- func (c *Client) Unlock(key string) (*models.ProjectLock, error)
- func (c *Client) UnlockByPull(repoFullName string, pullNum int) ([]models.ProjectLock, error)
- type Locker
- type NoOpLocker
- func (c *NoOpLocker) GetLock(key string) (*models.ProjectLock, error)
- func (c *NoOpLocker) List() (map[string]models.ProjectLock, error)
- func (c *NoOpLocker) TryLock(p models.Project, workspace string, pull models.PullRequest, user models.User) (TryLockResponse, error)
- func (c *NoOpLocker) Unlock(key string) (*models.ProjectLock, error)
- func (c *NoOpLocker) UnlockByPull(repoFullName string, pullNum int) ([]models.ProjectLock, error)
- type TryLockResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ApplyClient ¶
type ApplyClient struct {
// contains filtered or unexported fields
}
func (*ApplyClient) CheckApplyLock ¶
func (c *ApplyClient) CheckApplyLock() (ApplyCommandLock, error)
CheckApplyLock retrieves an apply command lock if present. If DisableApplyFlag is set it will always return a lock.
func (*ApplyClient) LockApply ¶
func (c *ApplyClient) LockApply() (ApplyCommandLock, error)
LockApply acquires global apply lock. DisableApplyFlag takes presedence to any existing locks, if it is set to true this function returns an error
func (*ApplyClient) UnlockApply ¶
func (c *ApplyClient) UnlockApply() error
UnlockApply releases a global apply lock. DisableApplyFlag takes presedence to any existing locks, if it is set to true this function returns an error
type ApplyCommandLock ¶
type ApplyCommandLock struct { // Locked is true is when apply commands are locked // Either by using DisableApply flag or creating a global ApplyCommandLock // DisableApply lock take precedence when set Locked bool Time time.Time Failure string }
ApplyCommandLock contains information about apply command lock status.
type ApplyLockChecker ¶
type ApplyLockChecker interface {
CheckApplyLock() (ApplyCommandLock, error)
}
ApplyLockChecker is an implementation of the global apply lock retrieval. It returns an object that contains information about apply locks status.
type ApplyLocker ¶
type ApplyLocker interface { // LockApply creates a lock for ApplyCommand if lock already exists it will // return existing lock without any changes LockApply() (ApplyCommandLock, error) // UnlockApply deletes apply lock created by LockApply if present, otherwise // it is a no-op UnlockApply() error ApplyLockChecker }
ApplyLocker interface that manages locks for apply command runner
func NewApplyClient ¶
func NewApplyClient(backend Backend, disableApplyFlag bool) ApplyLocker
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) LockCommand(cmdName command.Name, lockTime time.Time) (*command.Lock, error) UnlockCommand(cmdName command.Name) error CheckCommandLock(cmdName command.Name) (*command.Lock, 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 (*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 ¶
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 NoOpLocker ¶
type NoOpLocker struct{}
func NewNoOpLocker ¶
func NewNoOpLocker() *NoOpLocker
NewNoOpLocker returns a new lno operation lockingclient.
func (*NoOpLocker) GetLock ¶
func (c *NoOpLocker) 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 (*NoOpLocker) List ¶
func (c *NoOpLocker) 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 (*NoOpLocker) TryLock ¶
func (c *NoOpLocker) 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 (*NoOpLocker) Unlock ¶
func (c *NoOpLocker) 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 (*NoOpLocker) UnlockByPull ¶
func (c *NoOpLocker) UnlockByPull(repoFullName string, pullNum int) ([]models.ProjectLock, error)
UnlockByPull deletes all locks associated with that pull request.
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.