runstream

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApplyAction string = "apply"
	PlanAction  string = "plan"
)
View Source
const RunEventsStreamName = "RUN_EVENTS"
View Source
const RunMetadataKvBucket = "RUN_METADATA"
View Source
const RunPollingKvName = "POLLING_TASKS"
View Source
const RunPollingStreamNameV0 = "RUN_POLLING"
View Source
const TaskPollingDelayDefault = 10 * time.Second
View Source
const TaskPollingDelayMinimum = 1 * time.Second

Variables

View Source
var FailedResponse = []byte("failed")
View Source
var SuccessDoneResponse = []byte("done")
View Source
var SuccessResponse = []byte("success")

Functions

This section is empty.

Types

type RunEvent

type RunEvent interface {
	GetRunID() string
	GetContext() context.Context
	SetContext(context.Context)
	SetCarrier(map[string]string)
	GetNewStatus() string
	GetMetadata() RunMetadata
	SetMetadata(RunMetadata)
}

type RunMetadata

type RunMetadata interface {
	GetAction() string
	GetMRInternalID() int
	GetRootNoteID() int64
	GetMRProjectNameWithNamespace() string
	GetDiscussionID() string
	GetRunID() string
	GetWorkspace() string
	GetCommitSHA() string
	GetOrganization() string
	GetVcsProvider() string
	GetAutoMerge() bool
}

type RunPollingTask

type RunPollingTask interface {
	Schedule(ctx context.Context) error
	Reschedule(ctx context.Context) error
	Completed() error
	GetRunID() string
	GetContext() context.Context
	SetCarrier(map[string]string)
	GetLastStatus() string
	SetLastStatus(string)
	GetRunMetaData() RunMetadata
}

type Stream

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

func (*Stream) AddRunMeta

func (s *Stream) AddRunMeta(rmd RunMetadata) error

func (*Stream) GetRunMeta

func (s *Stream) GetRunMeta(runID string) (RunMetadata, error)

func (*Stream) HealthCheck

func (s *Stream) HealthCheck() error

func (*Stream) NewTFRunPollingTask

func (s *Stream) NewTFRunPollingTask(meta RunMetadata, delay time.Duration) RunPollingTask

func (*Stream) PublishTFRunEvent

func (s *Stream) PublishTFRunEvent(ctx context.Context, re RunEvent) error

func (*Stream) SubscribeTFRunEvents

func (s *Stream) SubscribeTFRunEvents(vcsProvider string, cb func(run RunEvent) bool) (closer func(), err error)

func (*Stream) SubscribeTFRunPollingTasks

func (s *Stream) SubscribeTFRunPollingTasks(cb func(task RunPollingTask) bool) (closer func(), err error)

type StreamClient

type StreamClient interface {
	HealthCheck() error
	PublishTFRunEvent(ctx context.Context, re RunEvent) error
	AddRunMeta(rmd RunMetadata) error
	GetRunMeta(runID string) (RunMetadata, error)
	NewTFRunPollingTask(meta RunMetadata, delay time.Duration) RunPollingTask
	SubscribeTFRunPollingTasks(cb func(task RunPollingTask) bool) (closer func(), err error)
	SubscribeTFRunEvents(queue string, cb func(run RunEvent) bool) (closer func(), err error)
}

func NewStream

func NewStream(js nats.JetStreamContext) StreamClient

type TFRunEvent

type TFRunEvent struct {
	RunID        string
	Organization string
	Workspace    string
	NewStatus    string
	Metadata     RunMetadata
	Carrier      propagation.MapCarrier `json:"Carrier"`
	// contains filtered or unexported fields
}

TFRunEvent represents a status change on a run

func (*TFRunEvent) GetContext added in v0.2.1

func (e *TFRunEvent) GetContext() context.Context

func (*TFRunEvent) GetMetadata

func (e *TFRunEvent) GetMetadata() RunMetadata

func (*TFRunEvent) GetNewStatus

func (e *TFRunEvent) GetNewStatus() string

func (*TFRunEvent) GetRunID

func (e *TFRunEvent) GetRunID() string

func (*TFRunEvent) SetCarrier added in v0.2.1

func (e *TFRunEvent) SetCarrier(carrier map[string]string)

func (*TFRunEvent) SetContext added in v0.2.1

func (e *TFRunEvent) SetContext(ctx context.Context)

func (*TFRunEvent) SetMetadata

func (e *TFRunEvent) SetMetadata(meta RunMetadata)

type TFRunMetadata

type TFRunMetadata struct {
	// RunID is the ID generated by TFC for the run
	RunID string
	// Organization is the TFC organization name
	Organization string
	// Workspace is the TFC workspace name
	Workspace string

	// Source is the trigger source of the TFC run
	// options include:
	// "merge_request" - for runs started via MR push or comment
	// "merge" - for runs started when MR is merged (apply after merge repos) (NOT IMPLEMENTED)
	// "slack" - for runs started via ChatOps (NOT IMPLEMENTED)
	Source string

	// Action is the triggered action (i.e. plan / apply)
	Action string

	// The git Commit SHA for which the run has been triggered
	CommitSHA string

	// MergeRequestProjectNameWithNamespace is the fully qualified Gitlab project name (e.g. /group/subgroup/project)
	MergeRequestProjectNameWithNamespace string

	// MergeRequestIID is the Gitlab Merge Request IID for which the Run has been triggered
	MergeRequestIID int

	// DiscussionID is the MergeRequest discussion thread where status updates should be written (optional)
	DiscussionID string
	// RootNoteID is the top level note of the discussion thread. It will be updated with progress info.
	RootNoteID int64

	VcsProvider string

	AutoMerge bool
}

func (*TFRunMetadata) GetAction

func (r *TFRunMetadata) GetAction() string

func (*TFRunMetadata) GetAutoMerge added in v0.3.0

func (r *TFRunMetadata) GetAutoMerge() bool

func (*TFRunMetadata) GetCommitSHA

func (r *TFRunMetadata) GetCommitSHA() string

func (*TFRunMetadata) GetDiscussionID

func (r *TFRunMetadata) GetDiscussionID() string

func (*TFRunMetadata) GetMRInternalID

func (r *TFRunMetadata) GetMRInternalID() int

func (*TFRunMetadata) GetMRProjectNameWithNamespace

func (r *TFRunMetadata) GetMRProjectNameWithNamespace() string

func (*TFRunMetadata) GetOrganization

func (r *TFRunMetadata) GetOrganization() string

func (*TFRunMetadata) GetRootNoteID

func (r *TFRunMetadata) GetRootNoteID() int64

func (*TFRunMetadata) GetRunID

func (r *TFRunMetadata) GetRunID() string

func (*TFRunMetadata) GetVcsProvider

func (r *TFRunMetadata) GetVcsProvider() string

func (*TFRunMetadata) GetWorkspace

func (r *TFRunMetadata) GetWorkspace() string

type TFRunPollingTask

type TFRunPollingTask struct {
	RunMetadata

	LastStatus string
	NextPoll   time.Time
	Processing bool
	LastUpdate time.Time

	// Revision is the NATS KV entry revision
	Revision uint64

	Carrier propagation.MapCarrier `json:"Carrier"`
	// contains filtered or unexported fields
}

func (*TFRunPollingTask) Completed

func (task *TFRunPollingTask) Completed() error

func (*TFRunPollingTask) GetContext added in v0.2.1

func (task *TFRunPollingTask) GetContext() context.Context

func (*TFRunPollingTask) GetLastStatus

func (task *TFRunPollingTask) GetLastStatus() string

func (*TFRunPollingTask) GetRunID

func (task *TFRunPollingTask) GetRunID() string

func (*TFRunPollingTask) GetRunMetaData

func (task *TFRunPollingTask) GetRunMetaData() RunMetadata

func (*TFRunPollingTask) Reschedule

func (task *TFRunPollingTask) Reschedule(ctx context.Context) error

func (*TFRunPollingTask) Schedule

func (task *TFRunPollingTask) Schedule(ctx context.Context) error

func (*TFRunPollingTask) SetCarrier added in v0.2.1

func (task *TFRunPollingTask) SetCarrier(carrier map[string]string)

func (*TFRunPollingTask) SetLastStatus

func (task *TFRunPollingTask) SetLastStatus(status string)

Jump to

Keyboard shortcuts

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