jobexecutor

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: MPL-2.0 Imports: 49 Imported by: 0

Documentation

Overview

Package jobexecutor package

Index

Constants

View Source
const (
	AnsiBoldRed   = "\033[31;1m"
	AnsiBoldGreen = "\033[32;1m"
	AnsiBoldCyan  = "\033[36;1m"
	AnsiReset     = "\033[0;m"
)

ANSI color constants for job log output

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplyHandler

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

ApplyHandler handles an apply job

func NewApplyHandler

func NewApplyHandler(
	cancellableCtx context.Context,
	jobCfg *JobConfig,
	workspaceDir string,
	workspace *types.Workspace,
	run *types.Run,
	jobLogger *jobLogger,
	client Client,
) *ApplyHandler

NewApplyHandler creates a new ApplyHandler

func (*ApplyHandler) Execute

func (a *ApplyHandler) Execute(ctx context.Context) error

Execute will execute the job

func (*ApplyHandler) OnError

func (a *ApplyHandler) OnError(ctx context.Context, _ error) error

OnError is called if the job returns an error while executing

func (*ApplyHandler) OnSuccess

func (a *ApplyHandler) OnSuccess(ctx context.Context) error

OnSuccess is called after the job has been executed successfully

type Client

type Client interface {
	GetRun(ctx context.Context, id string) (*types.Run, error)
	GetJob(ctx context.Context, id string) (*types.Job, error)
	GetWorkspace(ctx context.Context, id string) (*types.Workspace, error)
	GetRunVariables(ctx context.Context, runID string) ([]types.RunVariable, error)
	GetAssignedManagedIdentities(ctx context.Context, workspaceID string) ([]types.ManagedIdentity, error)
	GetConfigurationVersion(ctx context.Context, id string) (*types.ConfigurationVersion, error)
	CreateStateVersion(ctx context.Context, runID string, body io.Reader) (*types.StateVersion, error)
	CreateManagedIdentityCredentials(ctx context.Context, managedIdentityID string) ([]byte, error)
	CreateTerraformCLIDownloadURL(ctx context.Context, input *types.CreateTerraformCLIDownloadURLInput) (string, error)
	SaveJobLogs(ctx context.Context, jobID string, startOffset int, buffer []byte) error
	SubscribeToJobCancellationEvent(ctx context.Context, jobID string) (<-chan *types.CancellationEvent, error)
	UpdateApply(ctx context.Context, apply *types.Apply) (*types.Apply, error)
	UpdatePlan(ctx context.Context, apply *types.Plan) (*types.Plan, error)
	UploadPlanCache(ctx context.Context, plan *types.Plan, body io.Reader) error
	DownloadConfigurationVersion(ctx context.Context, configurationVersion *types.ConfigurationVersion, writer io.WriterAt) error
	DownloadStateVersion(ctx context.Context, stateVersion *types.StateVersion, writer io.WriterAt) error
	DownloadPlanCache(ctx context.Context, planID string, writer io.WriterAt) error
	Close() error
}

Client interface is used by the Job Executor to interface with the Tharsis API

func NewClient

func NewClient(apiURL string, token string) (Client, error)

NewClient creates an instance of the Client interface

type JobConfig

type JobConfig struct {
	JobID                 string
	APIEndpoint           string
	JobToken              string
	DiscoveryProtocolHost string
}

JobConfig is used to configure the job

type JobExecutor

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

JobExecutor executes a job

func NewJobExecutor

func NewJobExecutor(
	cfg *JobConfig,
	client Client,
	logger logger.Logger,
) *JobExecutor

NewJobExecutor creates a new JobExecutor

func (*JobExecutor) Execute

func (j *JobExecutor) Execute(ctx context.Context) error

Execute executes the job associated with the JobExecutor instance

type JobHandler

type JobHandler interface {
	Execute(ctx context.Context) error
	OnError(ctx context.Context, err error) error
	OnSuccess(ctx context.Context) error
}

JobHandler contains the job lifecycle functions

type LogBuffer

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

LogBuffer stores logs in a file and limits the amount of logs written

func NewLogBuffer

func NewLogBuffer() (*LogBuffer, error)

NewLogBuffer returns a new LogBuffer

func (*LogBuffer) Bytes

func (b *LogBuffer) Bytes(offset, n int) ([]byte, error)

Bytes returns a chunk of bytes from the log file

func (*LogBuffer) Checksum

func (b *LogBuffer) Checksum() string

Checksum returns the checksum for the log data

func (*LogBuffer) Close

func (b *LogBuffer) Close()

Close removes the underlying log file

func (*LogBuffer) SetLimit

func (b *LogBuffer) SetLimit(size int)

SetLimit sets the limit for log data in bytes

func (*LogBuffer) Size

func (b *LogBuffer) Size() int

Size returns the number of bytes written

func (*LogBuffer) Write

func (b *LogBuffer) Write(p []byte) (int, error)

type MemoryMonitor added in v0.4.0

type MemoryMonitor interface {
	Start(ctx context.Context)
	Stop()
}

MemoryMonitor implements all memory monitor functions. The methods should be called in the order shown here. GetMaxMemoryUsage can be called multiple times if desired.

func NewMemoryMonitor added in v0.4.0

func NewMemoryMonitor(jobLogger *jobLogger, memoryLimit uint64) (MemoryMonitor, error)

NewMemoryMonitor creates an instance of the memory monitor.

type PlanHandler

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

PlanHandler handles a plan job

func NewPlanHandler

func NewPlanHandler(
	cancellableCtx context.Context,
	jobCfg *JobConfig,
	workspaceDir string,
	workspace *types.Workspace,
	run *types.Run,
	jobLogger *jobLogger,
	client Client,
) *PlanHandler

NewPlanHandler creates a new PlanHandler

func (*PlanHandler) Execute

func (p *PlanHandler) Execute(ctx context.Context) error

Execute will execute the job

func (*PlanHandler) OnError

func (p *PlanHandler) OnError(ctx context.Context, _ error) error

OnError is called if the job returns an error while executing

func (*PlanHandler) OnSuccess

func (p *PlanHandler) OnSuccess(ctx context.Context) error

OnSuccess is called after the job has been executed successfully

Directories

Path Synopsis
Package managedidentity package
Package managedidentity package
awsfederated
Package awsfederated package
Package awsfederated package
azurefederated
Package azurefederated package
Package azurefederated package
tharsisfederated
Package tharsisfederated package
Package tharsisfederated package

Jump to

Keyboard shortcuts

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