Documentation
¶
Overview ¶
Package workloads contains high-level logic for managing the lifecycle of ToolHive-managed containers.
Index ¶
- Constants
- Variables
- func FilterByGroup(ctx context.Context, workloadList []core.Workload, groupName string) ([]core.Workload, error)
- func FilterByGroups(ctx context.Context, workloadList []core.Workload, groupNames []string) ([]core.Workload, error)
- func WorkloadFromContainerInfo(container *runtime.ContainerInfo) (core.Workload, error)
- type Manager
- type StatusManager
Constants ¶
const ( // AsyncOperationTimeout is the timeout for async workload operations AsyncOperationTimeout = 5 * time.Minute )
Variables ¶
var ( ErrWorkloadNotRunning = fmt.Errorf("workload not running") ErrInvalidWorkloadName = fmt.Errorf("invalid workload name") )
ErrWorkloadNotFound is returned when a container cannot be found by name. ErrInvalidWorkloadName is returned when a workload name fails validation.
Functions ¶
func FilterByGroup ¶ added in v0.2.3
func FilterByGroup( ctx context.Context, workloadList []core.Workload, groupName string, ) ([]core.Workload, error)
FilterByGroup filters workloads to only include those in the specified group
func FilterByGroups ¶ added in v0.2.4
func FilterByGroups( ctx context.Context, workloadList []core.Workload, groupNames []string, ) ([]core.Workload, error)
FilterByGroups filters workloads to only include those in the specified groups
func WorkloadFromContainerInfo ¶
func WorkloadFromContainerInfo(container *runtime.ContainerInfo) (core.Workload, error)
WorkloadFromContainerInfo creates a Workload struct from the runtime container info.
Types ¶
type Manager ¶
type Manager interface { // GetWorkload retrieves details of the named workload including its status. GetWorkload(ctx context.Context, workloadName string) (core.Workload, error) // ListWorkloads retrieves the states of all workloads. // The `listAll` parameter determines whether to include workloads that are not running. // The optional `labelFilters` parameter allows filtering workloads by labels (format: key=value). ListWorkloads(ctx context.Context, listAll bool, labelFilters ...string) ([]core.Workload, error) // DeleteWorkloads deletes the specified workloads by name. // It is implemented as an asynchronous operation which returns an errgroup.Group DeleteWorkloads(ctx context.Context, names []string) (*errgroup.Group, error) // StopWorkloads stops the specified workloads by name. // It is implemented as an asynchronous operation which returns an errgroup.Group StopWorkloads(ctx context.Context, names []string) (*errgroup.Group, error) // RunWorkload runs a container in the foreground. RunWorkload(ctx context.Context, runConfig *runner.RunConfig) error // RunWorkloadDetached runs a container in the background. RunWorkloadDetached(ctx context.Context, runConfig *runner.RunConfig) error // RestartWorkloads restarts the specified workloads by name. // It is implemented as an asynchronous operation which returns an errgroup.Group RestartWorkloads(ctx context.Context, names []string, foreground bool) (*errgroup.Group, error) // GetLogs retrieves the logs of a container. GetLogs(ctx context.Context, containerName string, follow bool) (string, error) // MoveToDefaultGroup moves the specified workloads to the default group by updating the runconfig. MoveToDefaultGroup(ctx context.Context, workloadNames []string, groupName string) error }
Manager is responsible for managing the state of ToolHive-managed containers. NOTE: This interface may be split up in future PRs, in particular, operations which are only relevant to the CLI/API use case will be split out.
func NewManager ¶
NewManager creates a new container manager instance.
func NewManagerFromRuntime ¶ added in v0.1.0
NewManagerFromRuntime creates a new container manager instance from an existing runtime.
type StatusManager ¶ added in v0.1.6
type StatusManager interface { // CreateWorkloadStatus creates the initial `starting` status for a new workload. // Unlike SetWorkloadStatus, this will create a new entry in the status store, // but will do nothing if the workload already exists. CreateWorkloadStatus(ctx context.Context, workloadName string) error // GetWorkload retrieves details of a workload by its name. GetWorkload(ctx context.Context, workloadName string) (core.Workload, error) // ListWorkloads returns details of all workloads. ListWorkloads(ctx context.Context, listAll bool, labelFilters []string) ([]core.Workload, error) // SetWorkloadStatus sets the status of a workload by its name. // Note that this does not return errors, but logs them instead. // This method will do nothing if the workload does not exist. SetWorkloadStatus(ctx context.Context, workloadName string, status rt.WorkloadStatus, contextMsg string) // DeleteWorkloadStatus removes the status of a workload by its name. DeleteWorkloadStatus(ctx context.Context, workloadName string) error }
StatusManager is an interface for fetching and retrieving workload statuses.
func NewFileStatusManager ¶ added in v0.2.1
func NewFileStatusManager(runtime rt.Runtime) StatusManager
NewFileStatusManager creates a new file-based StatusManager. Status files will be stored in the XDG data directory under "statuses/".
func NewStatusManagerFromRuntime ¶ added in v0.1.6
func NewStatusManagerFromRuntime(runtime rt.Runtime) StatusManager
NewStatusManagerFromRuntime creates a new instance of StatusManager from an existing runtime.