Help us shape the future of Go! Take the 2026 Go Developer Survey

workloads

package
v0.0.47 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package workloads contains high-level logic for managing the lifecycle of ToolHive-managed containers.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrContainerNotFound   = fmt.Errorf("container not found")
	ErrContainerNotRunning = fmt.Errorf("container not running")
)

ErrContainerNotFound is returned when a container cannot be found by name.

Functions

func CleanupTempPermissionProfile

func CleanupTempPermissionProfile(permissionProfilePath string) error

CleanupTempPermissionProfile removes a temporary permission profile file if it was created by toolhive

func CreatePermissionProfileFile

func CreatePermissionProfileFile(serverName string, permProfile *permissions.Profile) (string, error)

CreatePermissionProfileFile creates a temporary file with the permission profile

Types

type Manager

type Manager interface {
	// GetWorkload returns information about the named container.
	GetWorkload(ctx context.Context, name string) (Workload, error)
	// ListWorkloads lists all ToolHive-managed containers.
	ListWorkloads(ctx context.Context, listAll bool) ([]Workload, error)
	// DeleteWorkload deletes a container and its associated proxy process.
	// The container will be stopped if it is still running.
	DeleteWorkload(ctx context.Context, name string) error
	// StopWorkload stops a container and its associated proxy process.
	StopWorkload(ctx context.Context, name string) error
	// RunWorkload runs a container in the foreground.
	RunWorkload(ctx context.Context, runConfig *runner.RunConfig) error
	// RunWorkloadDetached runs a container in the background.
	RunWorkloadDetached(runConfig *runner.RunConfig) error
	// RestartWorkload restarts a previously stopped container.
	RestartWorkload(ctx context.Context, name string) error
}

Manager is responsible for managing the state of ToolHive-managed containers.

func NewManager

func NewManager(ctx context.Context) (Manager, error)

NewManager creates a new container manager instance.

type Workload

type Workload struct {
	// Name is the name of the workload.
	// It is used as a unique identifier.
	Name string `json:"name"`
	// Package specifies the Workload Package used to create this Workload.
	Package string `json:"package"`
	// URL is the URL of the workload exposed by the ToolHive proxy.
	URL string `json:"url"`
	// Port is the port on which the workload is exposed.
	// This is embedded in the URL.
	Port int `json:"port"`
	// ToolType is the type of tool this workload represents.
	// For now, it will always be "mcp" - representing an MCP server.
	ToolType string `json:"tool_type"`
	// Status is the current status of the workload.
	Status WorkloadStatus `json:"status"`
	// StatusContext provides additional context about the workload's status.
	// The exact meaning is determined by the status and the underlying runtime.
	StatusContext string `json:"status_context,omitempty"`
	// CreatedAt is the timestamp when the workload was created.
	CreatedAt time.Time `json:"created_at"`
}

Workload is a domain model representing a workload in the system. This is used in our API to hide details of the underlying runtime.

func WorkloadFromContainerInfo

func WorkloadFromContainerInfo(container *runtime.ContainerInfo) (Workload, error)

WorkloadFromContainerInfo creates a Workload struct from the runtime container info.

type WorkloadStatus

type WorkloadStatus string

WorkloadStatus is an enum representing the possible statuses of a workload.

const (
	// WorkloadStatusRunning indicates that the workload is currently running.
	WorkloadStatusRunning WorkloadStatus = "running"
	// WorkloadStatusStopped indicates that the workload is stopped.
	WorkloadStatusStopped WorkloadStatus = "stopped"
	// WorkloadStatusError indicates that the workload encountered an error.
	WorkloadStatusError WorkloadStatus = "error"
	// WorkloadStatusStarting indicates that the workload is in the process of starting.
	// TODO: this is not used yet.
	WorkloadStatusStarting WorkloadStatus = "starting"
	// WorkloadStatusUnknown indicates that the workload status is unknown.
	WorkloadStatusUnknown WorkloadStatus = "unknown"
)

Jump to

Keyboard shortcuts

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