bb

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogLevelTrace = iota
	LogLevelDebug
	LogLevelInfo
	LogLevelWarn
	LogLevelError
	LogLevelFatal
)
View Source
const (
	// WorkflowWait is an option to not start the dependent workflow until the other workflow
	// has completely finished (including all jobs). This is the default behaviour.
	WorkflowWait = WorkflowDependsOption("wait")
	// WorkflowConcurrent is an option to allow the dependent workflow to run concurrently with the
	// other workflow (as opposed to WaitForOtherWorkflowToFinish)
	WorkflowConcurrent = WorkflowDependsOption("concurrent")
	// WorkflowTerminateOnFailure will terminate the current process if the dependency workflow fails, instead
	// of starting the dependent workflow. This is the default behaviour.
	WorkflowTerminateOnFailure = WorkflowDependsOption("terminate-on-failure")
	// WorkflowStartOnFailure will start the dependent workflow even if the dependency workflow fails, instead
	// of terminating the process (as opposed to TerminateIfOtherWorkflowFails)
	WorkflowStartOnFailure = WorkflowDependsOption("start-on-failure")
)
View Source
const BuildDefinitionSyntaxVersion = "0.3"

BuildDefinitionSyntaxVersion is the version of the syntax used when submitting build definitions. This is equivalent to the 'version' field in YAML for statically-defined builds

View Source
const BuildResourceKind = "build"
View Source
const JobResourceKind = "job"
View Source
const ResourceNameRegexStr = "^[a-zA-Z0-9\\._-]{1,100}$"

Variables

View Source
var (
	Log             Logger   = DefaultLogger
	DefaultLogLevel LogLevel = LogLevelInfo
)

Functions

func AddWorkflows

func AddWorkflows(workflows ...*WorkflowDefinition)

AddWorkflows registers extra workflows to the set of workflows for the current build. This can be called from an init function prior to calling Workflows() from the main function.

func DefaultLogger

func DefaultLogger(level LogLevel, message string)

DefaultLogger is used by default if SetLogger() is not called, and outputs the log messages to stdout.

func GetAuthorizedContext

func GetAuthorizedContext(accessToken AccessToken) context.Context

GetAuthorizedContext returns a context that can be passed to generated OpenAPI functions to authenticate to the server. The context includes an "apikey" value containing the supplied JWT access token for authentication.

func NewBuildApiListArtifactsRequest

func NewBuildApiListArtifactsRequest(b *Build, workflow string, jobName string, groupName string, pageSize int) *client.ApiListArtifactsRequest

func NewLeveledLogger

func NewLeveledLogger(realLogger Logger) retryablehttp.LeveledLogger

NewLeveledLogger provides a retryablehttp.LeveledLogger interface on top of the basic Logger interface. This can be provided to retryableClient so that it can produce log messages at appropriate levels.

func SetDefaultLogLevel

func SetDefaultLogLevel(level LogLevel)

func SetLogger

func SetLogger(logger Logger)

SetLogger sets the logger function that will be called by the client code to log messages.

func Workflows

func Workflows(workflows ...*WorkflowDefinition)

Workflows defines a set of workflows for the current build, and begins processing workflows to submit jobs to the build. Returns when the workflow handler functions for all required workflows have completed.

Types

type AWSAuth

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

func NewAWSAuth

func NewAWSAuth() *AWSAuth

func (*AWSAuth) AccessKeyID

func (m *AWSAuth) AccessKeyID(accessKeyID string) *AWSAuth

func (*AWSAuth) AccessKeyIDFromSecret

func (m *AWSAuth) AccessKeyIDFromSecret(secretName string) *AWSAuth

func (*AWSAuth) Region

func (m *AWSAuth) Region(region string) *AWSAuth

func (*AWSAuth) SecretAccessKeyFromSecret

func (m *AWSAuth) SecretAccessKeyFromSecret(secretName string) *AWSAuth

type AccessToken

type AccessToken string

func ParseAccessToken

func ParseAccessToken(str string) (AccessToken, error)

func (AccessToken) String

func (t AccessToken) String() string

func (AccessToken) Validate

func (t AccessToken) Validate() error

type Artifact

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

func NewArtifact

func NewArtifact() *Artifact

func (*Artifact) GetData

func (a *Artifact) GetData() client.ArtifactDefinition

func (*Artifact) GetName

func (a *Artifact) GetName() ResourceName

func (*Artifact) Name

func (a *Artifact) Name(name string) *Artifact

func (*Artifact) Paths

func (a *Artifact) Paths(paths ...string) *Artifact

type ArtifactPage

type ArtifactPage struct {
	Artifacts []client.Artifact
	// contains filtered or unexported fields
}

ArtifactPage is a 'page' of artifacts, and allows the next and previous pages (if any) to be fetched.

func ListArtifacts

func ListArtifacts(b *Build, request *client.ApiListArtifactsRequest) (*ArtifactPage, error)

func NewArtifactPage

func NewArtifactPage(
	build *Build,
	request *client.ApiListArtifactsRequest,
	artifactsResult *client.ArtifactsPaginatedResponse,
) *ArtifactPage

func (*ArtifactPage) HasNext

func (p *ArtifactPage) HasNext() bool

func (*ArtifactPage) HasPrev

func (p *ArtifactPage) HasPrev() bool

func (*ArtifactPage) Next

func (p *ArtifactPage) Next() (*ArtifactPage, error)

func (*ArtifactPage) Prev

func (p *ArtifactPage) Prev() (*ArtifactPage, error)

type BasicAuth

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

func NewBasicAuth

func NewBasicAuth() *BasicAuth

func (*BasicAuth) PasswordFromSecret

func (m *BasicAuth) PasswordFromSecret(secretName string) *BasicAuth

func (*BasicAuth) Username

func (m *BasicAuth) Username(username string) *BasicAuth

func (*BasicAuth) UsernameFromSecret

func (m *BasicAuth) UsernameFromSecret(secretName string) *BasicAuth

type Build

type Build struct {
	ID             BuildID
	Name           ResourceName // name for this build (may actually be a number)
	OwnerName      string
	Ref            string
	DynamicJobID   JobID
	DynamicJobName ResourceName
	Repo           *Repo
	Commit         *Commit
	// workflowsToRun is a static list of workflows that were requested to be run when the build was queued;
	// an empty list means run all workflows
	WorkflowsToRun []ResourceName
	// contains filtered or unexported fields
}

func GetBuild

func GetBuild() (*Build, error)

func MustGetBuild

func MustGetBuild() *Build

func WorkflowsWithEnv

func WorkflowsWithEnv(
	envVars map[string]string,
	createNewWorkflowManager bool,
	workflows ...*WorkflowDefinition,
) (*Build, error)

WorkflowsWithEnv defines a set of workflows for the current build for use in testing, and begins processing workflows to submit jobs to the build. The build environment variable data is sourced from the specified string map rather than from actual environment variables, to facilitate passing test values. If createNewWorkflowManager is true then the global workflow manager is replaced with a new workflow manager, effectively removing all existing registered workflows in order to start a new test. Returns when the workflow handler functions for all required workflows have completed. If an error occurs while registering or starting workflows then the error is returned rather than the process being terminated.

func (*Build) GetAPIClient

func (b *Build) GetAPIClient() *client.APIClient

GetAPIClient returns the generated OpenAPI client, for directly calling API functions.

func (*Build) GetArtifactData

func (b *Build) GetArtifactData(artifactID string) ([]byte, error)

GetArtifactData returns the binary data for an artifact.

func (*Build) GetAuthorizedContext

func (b *Build) GetAuthorizedContext() context.Context

GetAuthorizedContext returns a context that can be passed to generated OpenAPI functions to authenticate to the server. The context includes an "apikey" value containing a JWT access token for authentication.

func (*Build) GetBuildGraph

func (b *Build) GetBuildGraph() (*client.BuildGraph, error)

GetBuildGraph reads the current build graph from the server. This will include all jobs and steps in the build, together with their current statuses.

func (*Build) GetJob

func (b *Build) GetJob(jobID JobID) (*client.Job, error)

GetJob reads information about the job with the specified Job ID from the server. This will include the current job status. but does not include information about the steps in the job; see GetJobGraph().

func (*Build) GetJobGraph

func (b *Build) GetJobGraph(jobID JobID) (*client.JobGraph, error)

GetJobGraph reads a job graph from the server for the specified job ID. This will include all steps in the job, together with the current job status.

func (*Build) GetLogDescriptor

func (b *Build) GetLogDescriptor(logDescriptorID string) (*client.LogDescriptor, error)

GetLogDescriptor returns a log descriptor containing information/metadata about a log (e.g. the log for a job or for a step).

func (*Build) ListArtifacts

func (b *Build) ListArtifacts(workflow string, jobName string, groupName string) (*ArtifactPage, error)

ListArtifacts reads information about selected artifacts from the current build. The first page of results will be returned in an ArtifactPage object. Call Next() on the returned object to get the next page of results, or Prev() to get the previous page.

func (*Build) ListArtifactsN

func (b *Build) ListArtifactsN(workflow string, jobName string, groupName string, pageSize int) (*ArtifactPage, error)

ListArtifactsN reads information about selected artifacts from the current build. The first page of up to pageSize results will be returned in an ArtifactPage object. Call Next() on the returned object to get the next page of results, or Prev() to get the previous page.

func (*Build) MustGetArtifactData added in v1.0.0

func (b *Build) MustGetArtifactData(artifactID string) []byte

MustGetArtifactData returns the binary data for an artifact. Terminates this program if a persistent error occurs.

func (*Build) MustGetBuildGraph added in v1.0.0

func (b *Build) MustGetBuildGraph() *client.BuildGraph

MustGetBuildGraph reads the current build graph from the server. This will include all jobs and steps in the build, together with their current statuses. Terminates this program if a persistent error occurs.

func (*Build) MustGetJob added in v1.0.0

func (b *Build) MustGetJob(jobID JobID) *client.Job

MustGetJob reads information about the job with the specified Job ID from the server. This will include the current job status. but does not include information about the steps in the job; see GetJobGraph(). Terminates this program if a persistent error occurs.

func (*Build) MustGetJobGraph

func (b *Build) MustGetJobGraph(jobID JobID) *client.JobGraph

MustGetJobGraph reads a job graph from the server for the specified job ID. This will include all steps in the job, together with the current job status. Terminates this program if a persistent error occurs.

func (*Build) MustGetLogDescriptor added in v1.0.0

func (b *Build) MustGetLogDescriptor(logDescriptorID string) *client.LogDescriptor

MustGetLogDescriptor returns a log descriptor containing information/metadata about a log (e.g. the log for a job or for a step). Terminates this program if a persistent error occurs.

func (*Build) MustListArtifacts added in v1.0.0

func (b *Build) MustListArtifacts(workflow string, jobName string, groupName string) *ArtifactPage

MustListArtifacts reads information about selected artifacts from the current build. The first page of results will be returned in an ArtifactPage object. Call Next() on the returned object to get the next page of results, or Prev() to get the previous page. Terminates this program if a persistent error occurs.

func (*Build) MustListArtifactsN added in v1.0.0

func (b *Build) MustListArtifactsN(workflow string, jobName string, groupName string, pageSize int) *ArtifactPage

MustListArtifactsN reads information about selected artifacts from the current build. The first page of up to pageSize results will be returned in an ArtifactPage object. Call Next() on the returned object to get the next page of results, or Prev() to get the previous page. Terminates this program if a persistent error occurs.

func (*Build) MustReadLogData added in v1.0.0

func (b *Build) MustReadLogData(logDescriptorID string, expand bool) io.ReadCloser

MustReadLogData returns a reader for fetching data for a log (e.g. the log for a job or for a step) as a series of JSON log entries. If expand is true then nested logs will be expanded and returned. Terminates this program if a persistent error occurs.

func (*Build) MustReadLogText added in v1.0.0

func (b *Build) MustReadLogText(logDescriptorID string, expand bool) io.ReadCloser

MustReadLogText returns a reader for fetching the data for a log in plain text (e.g. the log for a job or for a step). If expand is true then nested logs will be expanded and returned. Terminates this program if a persistent error occurs.

func (*Build) ReadLogData

func (b *Build) ReadLogData(logDescriptorID string, expand bool) (io.ReadCloser, error)

ReadLogData returns a reader for fetching data for a log (e.g. the log for a job or for a step) as a series of JSON log entries. If expand is true then nested logs will be expanded and returned.

func (*Build) ReadLogText

func (b *Build) ReadLogText(logDescriptorID string, expand bool) (io.ReadCloser, error)

ReadLogText returns a reader for fetching the data for a log in plain text (e.g. the log for a job or for a step). If expand is true then nested logs will be expanded and returned.

func (*Build) Shutdown

func (b *Build) Shutdown()

Shutdown performs a clean shutdown of all background Goroutines associated with this build. This is typically only required when running tests, where the process will be re-used.

type BuildID

type BuildID struct {
	ResourceID
}

func ParseBuildID

func ParseBuildID(str string) (BuildID, error)

type Commit

type Commit struct {
	SHA            string
	Message        string
	AuthorName     string
	AuthorEmail    string
	CommitterName  string
	CommitterEmail string
}

type ContextFactory

type ContextFactory func() context.Context

type DockerConfig

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

func NewDocker

func NewDocker() *DockerConfig

func (*DockerConfig) AWSAuth

func (config *DockerConfig) AWSAuth(auth *AWSAuth) *DockerConfig

AWSAuth configures AWS auth credentials for AWS ECR.

func (*DockerConfig) BasicAuth

func (config *DockerConfig) BasicAuth(auth *BasicAuth) *DockerConfig

BasicAuth configures basic auth credentials for the Docker registry.

func (*DockerConfig) GetData

func (config *DockerConfig) GetData() client.DockerConfigDefinition

func (*DockerConfig) Image

func (config *DockerConfig) Image(image string) *DockerConfig

func (*DockerConfig) Pull

func (config *DockerConfig) Pull(pullStrategy DockerPullStrategy) *DockerConfig

func (*DockerConfig) Shell

func (config *DockerConfig) Shell(shell string) *DockerConfig

type DockerPullStrategy

type DockerPullStrategy string
const (
	DockerPullDefault     DockerPullStrategy = "default"
	DockerPullNever       DockerPullStrategy = "never"
	DockerPullAlways      DockerPullStrategy = "always"
	DockerPullIfNotExists DockerPullStrategy = "if-not-exists"
)

func (DockerPullStrategy) String

func (ps DockerPullStrategy) String() string

type Env

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

func NewEnv

func NewEnv() *Env

func (*Env) Name

func (m *Env) Name(name string) *Env

func (*Env) Value

func (m *Env) Value(value string) *Env

func (*Env) ValueFromSecret

func (m *Env) ValueFromSecret(secretName string) *Env

type EventFilter

type EventFilter func(event *client.Event) bool

EventFilter is a function that returns true if the supplied event meets the criteria being evaluated when waiting for a job-related event. An EventFilter function should execute very quickly as it will be called frequently.

type EventManager

type EventManager struct {
	*StatefulService
	// contains filtered or unexported fields
}

func NewEventManager

func NewEventManager(
	apiClient *client.APIClient,
	authContextFactory ContextFactory,
	buildID BuildID,
	dynamicJobID JobID,
	logger Logger,
) *EventManager

NewEventManager creates an event manager that will poll for events for the specified build. The returned event manager will automatically start polling immediately, and will continue until Stop() is called.

func (*EventManager) GetStatsForWorkflow

func (m *EventManager) GetStatsForWorkflow(workflowName ResourceName) WorkflowStats

GetStatsForWorkflow returns statistics derived from events seen for the specified workflow. If no jobs or events have been seen for the workflow yet then a zero WorkflowStats object will be returned.

func (*EventManager) WaitForJobStatusChangedEvent

func (m *EventManager) WaitForJobStatusChangedEvent(ctx context.Context, filter EventFilter, jobs ...JobReference) (*client.Event, error)

WaitForJobStatusChangedEvent waits for a JobStatusChanged event for any of the specified jobs, that passes the supplied filter. Jobs with the specified workflows/names do not need to exist at the time of calling. If any suitable event already has been received then the function will immediately return the first suitable event. If no suitable event has already been received then the function will wait until a suitable event is received. If the caller wants to wait for events newer than some previously seen event, this should be done by supplying a suitable filter function that checks the SequenceNumber of candidate events.

type EventType

type EventType string
const (
	// EventTypeBuildStatusChanged is a type of event to notify subscribers that the status of a build has changed.
	// The event resource ID should be the ID of the build. The data should be a string of type WorkflowStatus.
	EventTypeBuildStatusChanged EventType = "BuildStatusChanged"

	// EventTypeJobStatusChanged is a type of event to notify subscribers that the status of a Job has changed.
	// The event resource ID should be the ID of the job. The data should be a string of type WorkflowStatus.
	EventTypeJobStatusChanged EventType = "JobStatusChanged"

	// EventTypeStepStatusChanged is a type of event to notify subscribers that the status of a Step has changed.
	// The event resource ID should be the ID of the step. The data should be a string of type WorkflowStatus.
	EventTypeStepStatusChanged EventType = "StepStatusChanged"
)

func (EventType) String

func (s EventType) String() string

type Job

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

func NewJob

func NewJob() *Job

func (*Job) Artifact

func (job *Job) Artifact(artifact *Artifact) *Job

func (*Job) Depends

func (job *Job) Depends(dependencies ...string) *Job

func (*Job) DependsOnJobArtifacts

func (job *Job) DependsOnJobArtifacts(jobs ...*Job) *Job

func (*Job) DependsOnJobs

func (job *Job) DependsOnJobs(jobs ...*Job) *Job

func (*Job) Desc

func (job *Job) Desc(description string) *Job

func (*Job) Docker

func (job *Job) Docker(dockerConfig *DockerConfig) *Job

func (*Job) Env

func (job *Job) Env(env *Env) *Job

func (*Job) Fingerprint

func (job *Job) Fingerprint(commands ...string) *Job

func (*Job) GetData

func (job *Job) GetData() client.JobDefinition

func (*Job) GetName

func (job *Job) GetName() ResourceName

GetName returns the name of the job (not including any workflow name).

func (*Job) GetReference

func (job *Job) GetReference() JobReference

GetReference returns a reference to the job, unique within the build. This will include any workflow the job is a part of.

func (*Job) Name

func (job *Job) Name(name ResourceName) *Job

func (*Job) OnCancelled

func (job *Job) OnCancelled(fn JobCallback) *Job

func (*Job) OnCompletion

func (job *Job) OnCompletion(fn JobCallback) *Job

func (*Job) OnFailure

func (job *Job) OnFailure(fn JobCallback) *Job

func (*Job) OnStatusChanged

func (job *Job) OnStatusChanged(fn JobCallback) *Job

OnStatusChanged will call a callback function each time the status of the job changes.

func (*Job) OnSuccess

func (job *Job) OnSuccess(fn JobCallback) *Job

func (*Job) RunsOn

func (job *Job) RunsOn(labels ...string) *Job

func (*Job) Service

func (job *Job) Service(service *Service) *Job

func (*Job) Step

func (job *Job) Step(step *Step) *Job

func (*Job) StepExecution

func (job *Job) StepExecution(executionType StepExecutionType) *Job

func (*Job) Type

func (job *Job) Type(jobType JobType) *Job

type JobCallback

type JobCallback func(event *JobStatusChangedEvent)

JobCallback is a function that can be called when a job has transitioned to a particular state.

type JobCallbackManager

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

JobCallbackManager tracks callbacks requested for when a job status changes.

func NewJobCallbackManager

func NewJobCallbackManager(eventManager *EventManager) *JobCallbackManager

func (*JobCallbackManager) AddSubscription

func (b *JobCallbackManager) AddSubscription(subscription *jobSubscription)

func (*JobCallbackManager) BlockAndProcessCallbacks

func (b *JobCallbackManager) BlockAndProcessCallbacks()

BlockAndProcessCallbacks will block and call callbacks until either all job callbacks have been run, or the build is finished. If there are no outstanding callbacks then this function will return immediately.

type JobID

type JobID struct {
	ResourceID
}

func ParseJobID

func ParseJobID(str string) (JobID, error)

type JobReference

type JobReference struct {
	Workflow ResourceName
	JobName  ResourceName
}

JobReference refers to a job within a specific workflow. An empty string for the workflow means the default workflow.

func GetJobRefOrNilFromEvent

func GetJobRefOrNilFromEvent(event *client.Event) *JobReference

GetJobRefOrNilFromEvent finds and returns a job reference from the specified event, or nil if the event has no job reference.

func NewJobReference

func NewJobReference(workflow ResourceName, jobName ResourceName) JobReference

func StringToJobReference

func StringToJobReference(ref string) JobReference

func (JobReference) Equals

func (j JobReference) Equals(ref JobReference) bool

func (JobReference) String

func (j JobReference) String() string

type JobStatusChangedEvent

type JobStatusChangedEvent struct {
	// The ID of the Job whose status has changed.
	JobID JobID
	// The name of the workflow the job is part of, or empty string for the default workflow.
	Workflow ResourceName
	// The name of the Job whose status has changed.
	JobName ResourceName
	// The new status of the Job
	JobStatus Status
	// The ID of the build this Job is a part of
	BuildID BuildID
	// The event data as it was delivered to the SDK.
	RawEvent *client.Event
}

func NewJobStatusChangedEvent

func NewJobStatusChangedEvent(rawEvent *client.Event) (*JobStatusChangedEvent, error)

type JobType

type JobType string
const (
	JobTypeDocker JobType = "docker"
	JobTypeExec   JobType = "exec"
)

func (JobType) String

func (t JobType) String() string

func (JobType) StringPtr

func (t JobType) StringPtr() *string

type LogLevel

type LogLevel int

func (LogLevel) String

func (l LogLevel) String() string

type Logger

type Logger func(level LogLevel, message string)

type Repo

type Repo struct {
	Name   ResourceName
	SSHURL string
	Link   string
}

type ResourceID

type ResourceID string

func ParseResourceID

func ParseResourceID(str string) (ResourceID, error)

func (ResourceID) Kind

func (s ResourceID) Kind() string

func (ResourceID) String

func (s ResourceID) String() string

func (ResourceID) Validate

func (s ResourceID) Validate() error

type ResourceName

type ResourceName string

ResourceName is a mutable, human-specified identifier of a resource. ResourceName must conform to length and character set requirements (see resourceNameMaxLength and resourceNameRegex). ResourceName is unique within a parent collection e.g. a repo's name must be unique within the legal entity it belongs to. Names should not be used as persistent references to a resource as they are mutable - use ResourceID instead.

func ParseResourceName

func ParseResourceName(str string) (ResourceName, error)

func ParseResourceNames

func ParseResourceNames(str string) ([]ResourceName, error)

ParseResourceNames parses a comma-separated list of resource names, validating each one.

func (ResourceName) String

func (s ResourceName) String() string

func (ResourceName) Validate

func (s ResourceName) Validate() error

type SecretName

type SecretName string

SecretName is the name of a secret used to provide a value for environment variables or authentication.

func (SecretName) String

func (s SecretName) String() string

type Service

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

func NewService

func NewService() *Service

func (*Service) AWSAuth

func (service *Service) AWSAuth(auth *AWSAuth) *Service

AWSAuth configures AWS auth credentials for AWS ECR.

func (*Service) BasicAuth

func (service *Service) BasicAuth(auth *BasicAuth) *Service

BasicAuth configures basic auth credentials for the Docker registry.

func (*Service) Env

func (service *Service) Env(env *Env) *Service

func (*Service) GetData

func (service *Service) GetData() client.ServiceDefinition

func (*Service) GetName

func (service *Service) GetName() ResourceName

func (*Service) Image

func (service *Service) Image(image string) *Service

func (*Service) Name

func (service *Service) Name(name string) *Service

type StatefulService

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

StatefulService provides standard service lifecycle routines (start/stop) functionality for long-lived services that run background threads.

func NewStatefulService

func NewStatefulService(ctx context.Context, log Logger, serviceName string, fn func()) *StatefulService

func (*StatefulService) Ctx

func (s *StatefulService) Ctx() context.Context

Ctx returns the service's context.

func (*StatefulService) Done

func (s *StatefulService) Done() <-chan struct{}

Done can be used to wait for the service to stop.

func (*StatefulService) Start

func (s *StatefulService) Start()

Start the service. Panics if called more than once.

func (*StatefulService) Stop

func (s *StatefulService) Stop()

Stop the service. Blocks until the service has cleaned up all background threads and exited. This function is idempotent.

type Status

type Status string
const (
	// StatusQueued indicates the item has been created and is waiting to be processed.
	StatusQueued Status = "queued"
	// StatusSubmitted indicates the item has been handed to a worker.
	StatusSubmitted Status = "submitted"
	// StatusRunning indicates the item is being processed.
	StatusRunning Status = "running"
	// StatusFailed indicates the item has failed during processing.
	StatusFailed Status = "failed"
	// StatusSucceeded indicates the item has successfully finished being processed.
	StatusSucceeded Status = "succeeded"
	// StatusCanceled indicates the item was canceled before it was ever processed.
	StatusCanceled Status = "canceled"
	// StatusUnknown indicates the item is in an unknown state.
	StatusUnknown Status = "unknown"
)

func (Status) HasFailed

func (s Status) HasFailed() bool

HasFailed returns true if the status indicates the workflow has either failed or been canceled.

func (Status) HasFinished

func (s Status) HasFinished() bool

HasFinished returns true if the status indicates the workflow has finished, either succeeded, failed, or canceled.

func (Status) String

func (s Status) String() string

type Step

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

func NewStep

func NewStep() *Step

func (*Step) Commands

func (step *Step) Commands(commands ...string) *Step

func (*Step) Depends

func (step *Step) Depends(stepNames ...string) *Step

func (*Step) DependsOnSteps

func (step *Step) DependsOnSteps(steps ...*Step) *Step

func (*Step) Desc

func (step *Step) Desc(description string) *Step

func (*Step) GetData

func (step *Step) GetData() client.StepDefinition

func (*Step) GetName

func (step *Step) GetName() ResourceName

func (*Step) Name

func (step *Step) Name(name string) *Step

type StepExecutionType

type StepExecutionType string
const (
	StepExecutionSequential StepExecutionType = "sequential"
	StepExecutionParallel   StepExecutionType = "parallel"
)

func (StepExecutionType) String

func (t StepExecutionType) String() string

type Workflow

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

func (*Workflow) GetBuild

func (w *Workflow) GetBuild() *Build

func (*Workflow) GetDefinition

func (w *Workflow) GetDefinition() WorkflowDefinition

func (*Workflow) GetName

func (w *Workflow) GetName() ResourceName

func (*Workflow) GetOutputOrNil

func (w *Workflow) GetOutputOrNil(outputName string) interface{}

GetOutputOrNil gets a previously set output value for the workflow, by name, If no output value from this workflow exists with the specified name then nil is immediately returned.

func (*Workflow) IsFailed

func (w *Workflow) IsFailed() bool

IsFailed returns true if any job or jobs in the workflow have failed, even if the workflow has not yet finished.

func (*Workflow) IsFinished

func (w *Workflow) IsFinished() bool

IsFinished returns true if the workflow function has returned and there are no unfinished jobs remaining in the workflow, i.e. if the workflow is completely finished.

func (*Workflow) IsWorkflowFinished

func (w *Workflow) IsWorkflowFinished(workflowName ResourceName) bool

IsWorkflowFinished returns true iff the specified workflow has completely finished.

func (*Workflow) Job

func (w *Workflow) Job(job *Job) *Workflow

func (*Workflow) MustSubmit

func (w *Workflow) MustSubmit(waitForCallbacks ...bool) []client.JobGraph

MustSubmit submits all newly created jobs to the server by calling Submit(), and returns the details for the newly created jobs. If an error is returned then the error is logged and this program exits with error code 1. If waitForCallbacks is true, or not specified, MustSubmit then waits until all outstanding callbacks have been called. If waitForCallbacks is specified as false, or if after submitting new jobs there are no outstanding callbacks, then MustSubmit returns immediately.

func (*Workflow) MustWaitForJob added in v1.0.0

func (w *Workflow) MustWaitForJob(jobs ...string) *JobStatusChangedEvent

MustWaitForJob waits until any of the specified jobs is finished, then returns the event that notified that the job is finished. This event includes the job's name, ID and final status. Jobs are specified by name, including the workflow, in the format 'workflow.jobname'. Any outstanding newly created jobs will be submitted to the server before waiting, via a call to MustSubmit(). Terminates this program if the build has finished without any event arriving that indicates one of the Jobs has finished.

func (*Workflow) MustWaitForOutput

func (w *Workflow) MustWaitForOutput(workflowName ResourceName, outputName string) interface{}

MustWaitForOutput waits until the workflow with the specified name has an output with the specified output name available, then returns the output value. Terminates this program if the workflow has finished without providing the output.

func (*Workflow) OnJobCancelled

func (w *Workflow) OnJobCancelled(jobRef JobReference, callback JobCallback)

func (*Workflow) OnJobCompletion

func (w *Workflow) OnJobCompletion(jobRef JobReference, callback JobCallback)

func (*Workflow) OnJobFailure

func (w *Workflow) OnJobFailure(jobRef JobReference, callback JobCallback)

func (*Workflow) OnJobStatusChanged

func (w *Workflow) OnJobStatusChanged(jobRef JobReference, callback JobCallback)

OnJobStatusChanged will call a callback function each time the status of a job changes.

func (*Workflow) OnJobSuccess

func (w *Workflow) OnJobSuccess(jobRef JobReference, callback JobCallback)

func (*Workflow) SetOutput

func (w *Workflow) SetOutput(outputName string, value interface{})

SetOutput sets an output value for the workflow, that can be used by other workflows. name is a name for the output, unique within this workflow. Any existing value with this name will be overwritten. value is the data for the output. Any object supplied as data should ideally be immutable, and at the very least be thread-safe so that it can be read by other workflows from other goroutines.

func (*Workflow) Submit

func (w *Workflow) Submit(waitForCallbacks ...bool) ([]client.JobGraph, error)

Submit submits all newly created jobs to the server and returns the details for the newly created jobs. If waitForCallbacks is true, or not specified, Submit then waits until all outstanding callbacks have been called. If waitForCallbacks is specified as false, or if after submitting new jobs there are no outstanding callbacks, then Submit returns immediately.

func (*Workflow) WaitForJob

func (w *Workflow) WaitForJob(jobs ...string) (*JobStatusChangedEvent, error)

WaitForJob waits until any of the specified jobs is finished, then returns the event that notified that the job is finished. This event includes the job's name, ID and final status. Jobs are specified by name, including the workflow, in the format 'workflow.jobname'. Any outstanding newly created jobs will be submitted to the server before waiting, via a call to MustSubmit().

func (*Workflow) WaitForOutput

func (w *Workflow) WaitForOutput(workflowName ResourceName, outputName string) (interface{}, error)

WaitForOutput waits until the workflow with the specified name has an output with the specified output name available, then returns the output value. Returns an error if the workflow has finished without providing the output.

func (*Workflow) WaitForWorkflow

func (w *Workflow) WaitForWorkflow(workflowName ResourceName) *Workflow

WaitForWorkflow waits until the workflow with the specified name has completely finished. Returns the workflow that has now finished; this can be used to check for failure by calling IsFailed()

type WorkflowDefinition

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

func NewWorkflow

func NewWorkflow() *WorkflowDefinition

func (*WorkflowDefinition) Depends

func (w *WorkflowDefinition) Depends(workflowName ResourceName, options ...WorkflowDependsOption) *WorkflowDefinition

Depends indicates that the specified workflow depends on another workflow. The specified options determine the exact behaviour; the default is to wait until the specified workflow is fully finished before running this workflow, and to terminate this process if the specified workflow fails.

func (*WorkflowDefinition) GetName

func (w *WorkflowDefinition) GetName() ResourceName

func (*WorkflowDefinition) Handler

func (*WorkflowDefinition) Name

func (*WorkflowDefinition) SubmitFailureIsFatal

func (w *WorkflowDefinition) SubmitFailureIsFatal(isFatal bool) *WorkflowDefinition

type WorkflowDependsOption

type WorkflowDependsOption string

type WorkflowHandler

type WorkflowHandler func(workflow *Workflow) error

WorkflowHandler is a function that can create the jobs required for a particular workflow.

type WorkflowStats

type WorkflowStats struct {
	FinishedJobCount   int
	UnfinishedJobCount int
	FailedJobCount     int
}

WorkflowStats contains statistics about a workflow

type WorkflowStatsMap

type WorkflowStatsMap map[ResourceName]*WorkflowStats

WorkflowStatsMap maps workflow name to statistics for the workflow

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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