Documentation ¶
Index ¶
- Constants
- Variables
- func NewRawPGClient(pguri string, maxconns uint32) (*pgxpool.Pool, error)
- type DataLayer
- type FakeDataLayer
- func (fdl *FakeDataLayer) AddEvent(ctx context.Context, id uuid.UUID, event string) error
- func (fdl *FakeDataLayer) CancelBuild(ctx context.Context, id uuid.UUID) error
- func (fdl *FakeDataLayer) CancellationListeners() uint
- func (fdl *FakeDataLayer) CreateAPIKey(ctx context.Context, ak models.APIKey) (uuid.UUID, error)
- func (fdl *FakeDataLayer) CreateBuild(ctx context.Context, b *models.Build) (uuid.UUID, error)
- func (fdl *FakeDataLayer) DeleteAPIKey(ctx context.Context, id uuid.UUID) error
- func (fdl *FakeDataLayer) DeleteBuild(ctx context.Context, id uuid.UUID) error
- func (fdl *FakeDataLayer) GetAPIKey(ctx context.Context, id uuid.UUID) (models.APIKey, error)
- func (fdl *FakeDataLayer) GetBuildByID(ctx context.Context, id uuid.UUID) (*models.Build, error)
- func (fdl *FakeDataLayer) GetRootAPIKey(ctx context.Context) (models.APIKey, error)
- func (fdl *FakeDataLayer) ListBuilds(ctx context.Context, opts ListBuildsOptions) ([]*models.Build, error)
- func (fdl *FakeDataLayer) ListenForBuildCompleted(ctx context.Context, id uuid.UUID) (models.BuildStatus, error)
- func (fdl *FakeDataLayer) ListenForBuildEvents(ctx context.Context, id uuid.UUID, c chan<- string) error
- func (fdl *FakeDataLayer) ListenForBuildRunning(ctx context.Context, id uuid.UUID) error
- func (fdl *FakeDataLayer) ListenForCancellation(ctx context.Context, id uuid.UUID) error
- func (fdl *FakeDataLayer) SetBuildAsCompleted(ctx context.Context, id uuid.UUID, status models.BuildStatus) error
- func (fdl *FakeDataLayer) SetBuildAsRunning(ctx context.Context, id uuid.UUID) error
- func (fdl *FakeDataLayer) SetBuildCompletedTimestamp(ctx context.Context, id uuid.UUID, ts time.Time) error
- func (fdl *FakeDataLayer) SetBuildStatus(ctx context.Context, id uuid.UUID, s models.BuildStatus) error
- type ListBuildsOptions
- type PostgresDBLayer
- func (dl *PostgresDBLayer) AddEvent(ctx context.Context, id uuid.UUID, event string) error
- func (dl *PostgresDBLayer) CancelBuild(ctx context.Context, id uuid.UUID) error
- func (dl *PostgresDBLayer) Close()
- func (dl *PostgresDBLayer) CreateAPIKey(ctx context.Context, apikey models.APIKey) (uuid.UUID, error)
- func (dl *PostgresDBLayer) CreateBuild(ctx context.Context, b *models.Build) (uuid.UUID, error)
- func (dl *PostgresDBLayer) CreateSeedAPIKey(ctx context.Context, id uuid.UUID) error
- func (dl *PostgresDBLayer) DeleteAPIKey(ctx context.Context, id uuid.UUID) error
- func (dl *PostgresDBLayer) DeleteBuild(ctx context.Context, id uuid.UUID) (err error)
- func (dl *PostgresDBLayer) GetAPIKey(ctx context.Context, id uuid.UUID) (models.APIKey, error)
- func (dl *PostgresDBLayer) GetBuildByID(ctx context.Context, id uuid.UUID) (*models.Build, error)
- func (dl *PostgresDBLayer) GetRootAPIKey(ctx context.Context) (models.APIKey, error)
- func (dl *PostgresDBLayer) ListBuilds(ctx context.Context, opts ListBuildsOptions) ([]*models.Build, error)
- func (dl *PostgresDBLayer) ListenForBuildCompleted(ctx context.Context, id uuid.UUID) (models.BuildStatus, error)
- func (dl *PostgresDBLayer) ListenForBuildEvents(ctx context.Context, id uuid.UUID, c chan<- string) error
- func (dl *PostgresDBLayer) ListenForBuildRunning(ctx context.Context, id uuid.UUID) error
- func (dl *PostgresDBLayer) ListenForCancellation(ctx context.Context, id uuid.UUID) error
- func (dl *PostgresDBLayer) SetBuildAsCompleted(ctx context.Context, id uuid.UUID, status models.BuildStatus) error
- func (dl *PostgresDBLayer) SetBuildAsRunning(ctx context.Context, id uuid.UUID) error
- func (dl *PostgresDBLayer) SetBuildCompletedTimestamp(ctx context.Context, id uuid.UUID, completed time.Time) error
- func (dl *PostgresDBLayer) SetBuildStatus(ctx context.Context, id uuid.UUID, s models.BuildStatus) error
Constants ¶
const ( MinPoolConns uint32 = 2 MaxPoolConns uint32 = 10 MaxListenPoolConns uint32 = 100 )
Variables ¶
var ErrNotFound = fmt.Errorf("not found")
Functions ¶
Types ¶
type DataLayer ¶
type DataLayer interface { CreateBuild(context.Context, *models.Build) (uuid.UUID, error) GetBuildByID(context.Context, uuid.UUID) (*models.Build, error) ListBuilds(context.Context, ListBuildsOptions) ([]*models.Build, error) SetBuildCompletedTimestamp(context.Context, uuid.UUID, time.Time) error SetBuildStatus(context.Context, uuid.UUID, models.BuildStatus) error DeleteBuild(context.Context, uuid.UUID) error CancelBuild(context.Context, uuid.UUID) error ListenForCancellation(context.Context, uuid.UUID) error ListenForBuildEvents(ctx context.Context, id uuid.UUID, c chan<- string) error AddEvent(ctx context.Context, id uuid.UUID, event string) error SetBuildAsRunning(ctx context.Context, id uuid.UUID) error ListenForBuildRunning(ctx context.Context, id uuid.UUID) error SetBuildAsCompleted(ctx context.Context, id uuid.UUID, status models.BuildStatus) error ListenForBuildCompleted(ctx context.Context, id uuid.UUID) (models.BuildStatus, error) CreateAPIKey(ctx context.Context, apikey models.APIKey) (uuid.UUID, error) GetRootAPIKey(ctx context.Context) (models.APIKey, error) GetAPIKey(ctx context.Context, id uuid.UUID) (models.APIKey, error) DeleteAPIKey(ctx context.Context, id uuid.UUID) error }
DataLayer describes an object that interacts with a data store
type FakeDataLayer ¶
type FakeDataLayer struct {
// contains filtered or unexported fields
}
func (*FakeDataLayer) CancelBuild ¶
func (*FakeDataLayer) CancellationListeners ¶
func (fdl *FakeDataLayer) CancellationListeners() uint
func (*FakeDataLayer) CreateAPIKey ¶
func (*FakeDataLayer) CreateBuild ¶
func (*FakeDataLayer) DeleteAPIKey ¶
func (*FakeDataLayer) DeleteBuild ¶
func (*FakeDataLayer) GetBuildByID ¶
func (*FakeDataLayer) GetRootAPIKey ¶
func (*FakeDataLayer) ListBuilds ¶
func (fdl *FakeDataLayer) ListBuilds(ctx context.Context, opts ListBuildsOptions) ([]*models.Build, error)
func (*FakeDataLayer) ListenForBuildCompleted ¶
func (fdl *FakeDataLayer) ListenForBuildCompleted(ctx context.Context, id uuid.UUID) (models.BuildStatus, error)
func (*FakeDataLayer) ListenForBuildEvents ¶
func (*FakeDataLayer) ListenForBuildRunning ¶
func (*FakeDataLayer) ListenForCancellation ¶
func (*FakeDataLayer) SetBuildAsCompleted ¶
func (fdl *FakeDataLayer) SetBuildAsCompleted(ctx context.Context, id uuid.UUID, status models.BuildStatus) error
func (*FakeDataLayer) SetBuildAsRunning ¶
func (*FakeDataLayer) SetBuildCompletedTimestamp ¶
func (*FakeDataLayer) SetBuildStatus ¶
func (fdl *FakeDataLayer) SetBuildStatus(ctx context.Context, id uuid.UUID, s models.BuildStatus) error
type ListBuildsOptions ¶
type ListBuildsOptions struct { WithGitHubRepo string WithGitHubRef string WithImageRepo string WithStatus models.BuildStatus CompletedAfter time.Time // after or equal to StartedAfter time.Time // after or equal to CompletedBefore time.Time StartedBefore time.Time Limit uint // Return no more than this many builds }
ListBuildsOptions models all options for listing builds. Fields (when set) are combined with an implicit AND. If you supply impossible options, no builds will be returned.
type PostgresDBLayer ¶
type PostgresDBLayer struct {
// contains filtered or unexported fields
}
PostgresDBLayer is a DataLayer instance that utilizes a PostgreSQL database
func NewPostgresDBLayer ¶
func NewPostgresDBLayer(pguri string) (*PostgresDBLayer, error)
NewPostgresDBLayer returns a data layer object backed by PostgreSQL
func (*PostgresDBLayer) AddEvent ¶
AddEvent appends an event to a build and notifies any listeners to that channel
func (*PostgresDBLayer) CancelBuild ¶
CancelBuild broadcasts a cancellation request for build id
func (*PostgresDBLayer) Close ¶
func (dl *PostgresDBLayer) Close()
Close closes all database connections in the connection pool
func (*PostgresDBLayer) CreateAPIKey ¶
func (dl *PostgresDBLayer) CreateAPIKey(ctx context.Context, apikey models.APIKey) (uuid.UUID, error)
CreateAPIKey creates a new API key with a random UUID
func (*PostgresDBLayer) CreateBuild ¶
CreateBuild inserts a new build into the DB returning the ID
func (*PostgresDBLayer) CreateSeedAPIKey ¶
CreateSeedAPIKey creates a new "seed" API key for testing environments This isn't part of the DataLayer interface because it is not for general use
func (*PostgresDBLayer) DeleteAPIKey ¶
func (*PostgresDBLayer) DeleteBuild ¶
DeleteBuild removes a build from the DB.
func (*PostgresDBLayer) GetBuildByID ¶
GetBuildByID fetches a build object from the DB
func (*PostgresDBLayer) GetRootAPIKey ¶
GetRootAPIKey gets the initial root API key created when the application was bootstrapped
func (*PostgresDBLayer) ListBuilds ¶
func (dl *PostgresDBLayer) ListBuilds(ctx context.Context, opts ListBuildsOptions) ([]*models.Build, error)
ListBuilds lists all builds according to opts. At least one field of opts must be a non-zero value.
func (*PostgresDBLayer) ListenForBuildCompleted ¶
func (dl *PostgresDBLayer) ListenForBuildCompleted(ctx context.Context, id uuid.UUID) (models.BuildStatus, error)
ListenForBuildCompleted blocks and listens for a build to be updated to completed. If build is already completed, this method will return immediately. If it hasn't completed, it must be in NotStarted or Running status or an error will be returned. If a notification is received, the completed build status and a nil error are returned
func (*PostgresDBLayer) ListenForBuildEvents ¶
func (dl *PostgresDBLayer) ListenForBuildEvents(ctx context.Context, id uuid.UUID, c chan<- string) error
ListenForBuildEvents blocks and listens for the build events to occur for a build, writing any events that are received to c. If build is not currently listenable an error will be returned immediately. Always returns a non-nil error.
func (*PostgresDBLayer) ListenForBuildRunning ¶
ListenForBuildRunning blocks and listens for a build to be updated to Running. If it's already running, this method returns immediately. If the build is in any status other than NotStarted or Running, an error is returned. If a notification is received, a nil error will be returned
func (*PostgresDBLayer) ListenForCancellation ¶
ListenForCancellation blocks and listens for cancellation requests for build id. If a cancellation request is received a nil error will be returned.
func (*PostgresDBLayer) SetBuildAsCompleted ¶
func (dl *PostgresDBLayer) SetBuildAsCompleted(ctx context.Context, id uuid.UUID, status models.BuildStatus) error
SetBuildAsCompleted updates build status to completed (success, failure, skipped) and sends a notification for listeners
func (*PostgresDBLayer) SetBuildAsRunning ¶
SetBuildAsRunning updates build status to Running and sends a notification for listeners
func (*PostgresDBLayer) SetBuildCompletedTimestamp ¶
func (*PostgresDBLayer) SetBuildStatus ¶
func (dl *PostgresDBLayer) SetBuildStatus(ctx context.Context, id uuid.UUID, s models.BuildStatus) error