worker

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DbFilemode = os.FileMode(0600)
)

Variables

View Source
var (
	DbFilename      = "%s.db" // %s is substituted with the worker's name
	DbBucketName    = "tasks"
	DbLogBucketName = "logs"

	LogCaptureMaxLines = 1000

	LoopInterval = 10 * time.Second
)
View Source
var ApiShutdownTimeout = 10 * time.Second

Functions

This section is empty.

Types

type Api

type Api struct {
	Address string
	Port    int
	Worker  *Worker
	Router  *chi.Mux

	// TLSConfig enables HTTPS when non-nil
	// a non-nil config with client ClientCAs set additionally requires the
	// manager to authenticate with a cluster certificate via mTLS,
	// so only certificate holders may start, stop or inspect tasks on this worker
	TLSConfig *tls.Config
	// contains filtered or unexported fields
}

func (*Api) ForgetTaskHandler

func (a *Api) ForgetTaskHandler(w http.ResponseWriter, r *http.Request)

func (*Api) GetPortsHandler

func (a *Api) GetPortsHandler(w http.ResponseWriter, r *http.Request)

func (*Api) GetStatsHandler

func (a *Api) GetStatsHandler(w http.ResponseWriter, r *http.Request)

func (*Api) GetTaskLogsHandler

func (a *Api) GetTaskLogsHandler(w http.ResponseWriter, r *http.Request)

func (*Api) GetTasksHandler

func (a *Api) GetTasksHandler(w http.ResponseWriter, r *http.Request)

func (*Api) PullImageHandler

func (a *Api) PullImageHandler(w http.ResponseWriter, r *http.Request)

pulls the requested image on this worker's docker daemon. the pull is synchronous and can take a while for large images. callers should use a bigger client timeout than default

func (*Api) Shutdown

func (a *Api) Shutdown() error

func (*Api) Start

func (a *Api) Start() error

func (*Api) StartTaskHandler

func (a *Api) StartTaskHandler(w http.ResponseWriter, r *http.Request)

type OccupiedPorts

type OccupiedPorts struct {
	TCP []int `json:"tcp,omitempty"`
	UDP []int `json:"udp,omitempty"`
}

type PullImageRequest

type PullImageRequest struct {
	Image string `json:"image"`
}

request/response bodies for POST /images (pull an image on this worker)

type PullImageResponse

type PullImageResponse struct {
	Image  string `json:"image"`
	Pulled bool   `json:"pulled"` // false = the image was already present locally
}

type TaskLogsResult

type TaskLogsResult struct {
	Logs     []byte
	State    task.State
	ExitCode *int
	Live     bool // true = logs came from a live/exited container, false = from LogDb
}

type Worker

type Worker struct {
	Name  string
	Queue *queue.Queue[task.Task]
	Db    store.Store[task.Task]
	LogDb store.Store[task.TaskLogs]
	Stats *stats.Stats
	// contains filtered or unexported fields
}

func New

func New(name, dbType string) (*Worker, error)

func (*Worker) AddTask

func (w *Worker) AddTask(t task.Task) error

func (*Worker) Close

func (w *Worker) Close() error

func (*Worker) CollectStats

func (w *Worker) CollectStats(ctx context.Context)

func (*Worker) ForgetTask

func (w *Worker) ForgetTask(id uuid.UUID) error

func (*Worker) GetTaskLogs

func (w *Worker) GetTaskLogs(t task.Task, tail int) TaskLogsResult

func (*Worker) HostPortsWithError

func (w *Worker) HostPortsWithError() (OccupiedPorts, error)

func (*Worker) InspectTask

func (w *Worker) InspectTask(t task.Task) task.DockerInspectResponse

func (*Worker) PullImage

func (w *Worker) PullImage(image string) (bool, error)

func (*Worker) RunTasks

func (w *Worker) RunTasks(ctx context.Context)

func (*Worker) StartTask

func (w *Worker) StartTask(t task.Task) task.DockerResult

func (*Worker) StopTask

func (w *Worker) StopTask(t task.Task) task.DockerResult

func (*Worker) UpdateTasks

func (w *Worker) UpdateTasks(ctx context.Context)

Jump to

Keyboard shortcuts

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