Thanks to visit codestin.com
Credit goes to pkg.go.dev

agentscripts

package
v2.21.3 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2025 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTimeout is returned when a script times out.
	ErrTimeout = xerrors.New("script timed out")
	// ErrOutputPipesOpen is returned when a script exits leaving the output
	// pipe(s) (stdout, stderr) open. This happens because we set WaitDelay on
	// the command, which gives us two things:
	//
	// 1. The ability to ensure that a script exits (this is important for e.g.
	//    blocking login, and avoiding doing so indefinitely)
	// 2. Improved command cancellation on timeout
	ErrOutputPipesOpen = xerrors.New("script exited without closing output pipes")
)

Functions

This section is empty.

Types

type ExecuteOption added in v2.16.0

type ExecuteOption int

ExecuteOption describes what scripts we want to execute.

const (
	ExecuteAllScripts ExecuteOption = iota
	ExecuteStartScripts
	ExecutePostStartScripts
	ExecuteStopScripts
	ExecuteCronScripts
)

ExecuteOption enums.

type InitOption added in v2.21.0

type InitOption func(*Runner)

InitOption describes an option for the runner initialization.

func WithPostStartScripts added in v2.21.0

func WithPostStartScripts(scripts ...codersdk.WorkspaceAgentScript) InitOption

WithPostStartScripts adds scripts that should be run after the workspace start scripts but before the workspace is marked as started.

type Options

type Options struct {
	DataDirBase     string
	LogDir          string
	Logger          slog.Logger
	SSHServer       *agentssh.Server
	Filesystem      afero.Fs
	GetScriptLogger func(logSourceID uuid.UUID) ScriptLogger
}

Options are a set of options for the runner.

type Runner

type Runner struct {
	Options
	// contains filtered or unexported fields
}

func New

func New(opts Options) *Runner

New creates a runner for the provided scripts.

func (*Runner) Close

func (r *Runner) Close() error

func (*Runner) DataDir added in v2.9.0

func (r *Runner) DataDir() string

DataDir returns the directory where scripts data is stored.

func (*Runner) Execute

func (r *Runner) Execute(ctx context.Context, option ExecuteOption) error

Execute runs a set of scripts according to a filter.

func (*Runner) Init

func (r *Runner) Init(scripts []codersdk.WorkspaceAgentScript, scriptCompleted ScriptCompletedFunc, opts ...InitOption) error

Init initializes the runner with the provided scripts. It also schedules any scripts that have a schedule. This function must be called before Execute.

func (*Runner) RegisterMetrics added in v2.5.1

func (r *Runner) RegisterMetrics(reg prometheus.Registerer)

func (*Runner) ScriptBinDir added in v2.9.0

func (r *Runner) ScriptBinDir() string

ScriptBinDir returns the directory where scripts can store executable binaries.

func (*Runner) StartCron

func (r *Runner) StartCron()

StartCron starts the cron scheduler. This is done async to allow for the caller to execute scripts prior.

type ScriptLogger added in v2.9.0

type ScriptLogger interface {
	Send(ctx context.Context, log ...agentsdk.Log) error
	Flush(context.Context) error
}

Jump to

Keyboard shortcuts

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