task

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: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionStart   Action = "start"
	ActionStop    Action = "stop"
	ResultSuccess Result = "success"
)
View Source
const (
	RestartPolicyNone          = "no"
	RestartPolicyAlways        = "always"
	RestartPolicyOnFailure     = "on-failure"
	RestartPolicyUnlessStopped = "unless-stopped"
)

restart policies a task can declare

Variables

View Source
var (
	HealthCheckDefaultInterval    = 30
	HealthCheckDefaultTimeout     = 5
	HealthCheckDefaultRetries     = 3
	HealthCheckDefaultStartPeriod = 0
)

Functions

func ShouldRestart

func ShouldRestart(policy string) bool

reports whether a Failed task with this policy may be restarted by the orchestrator

func ShouldRestartOnSuccess

func ShouldRestartOnSuccess(policy string) bool

reports whether a cleanly exited task with this policy may be restarted by the orchestrator

func ValidStateTransition

func ValidStateTransition(from, to State) bool

func ValidateEnv

func ValidateEnv(env []string) error

validates env entries in KEY=VALUE form

func ValidatePortMappings

func ValidatePortMappings(mappings []PortMapping) error

SCTP is intentionally unsupported, since the worker has no reliable SCTP inventory

func ValidateRestartPolicy

func ValidateRestartPolicy(p string) error

accepts an empty policy, defaults to on-failure

func ValidateSecurity added in v0.1.1

func ValidateSecurity(s *Security) error

validates a Security block; nil is valid ("no security options")

Types

type Action

type Action string

type Config

type Config struct {
	Name          string
	AttachStdin   bool
	AttachStdout  bool
	AttachStderr  bool
	Ports         []PortMapping
	Cmd           []string
	Image         string
	Cpu           float64
	Memory        int64
	Disk          int64
	Env           []string
	RestartPolicy string
	HealthCheck   *HealthCheck
	Security      *Security
}

func NewConfig

func NewConfig(t *Task) *Config

type Docker

type Docker struct {
	Client *client.Client
	Config Config
}

func NewDocker

func NewDocker(c *Config) (*Docker, error)

func (*Docker) Inspect

func (d *Docker) Inspect(containerID string) DockerInspectResponse

func (*Docker) Logs

func (d *Docker) Logs(containerID string, tail int) ([]byte, error)

fetches the demultiplexed stdout+stderr of a container into a single buffer a missing container yields (nil, nil) so callers can fall back to stored logs without treating that as an error

func (*Docker) Pull

func (d *Docker) Pull(image string) (bool, error)

makes sure image exists on the local daemon, pulling it from the registry only when missing

it reports whether the image had to be pulled

the pull's progress stream is drained rather than printed, callers get a plain success/error

func (*Docker) Run

func (d *Docker) Run() DockerResult

func (*Docker) Stop

func (d *Docker) Stop(id string) DockerResult

type DockerInspectResponse

type DockerInspectResponse struct {
	Response *container.InspectResponse
	Error    error
}

type DockerResult

type DockerResult struct {
	ContainerID string
	Action      Action
	Result      Result
	ExitCode    *int // container exit code, when known
	Error       error
}

type HealthCheck

type HealthCheck struct {
	Type        HealthCheckType
	Port        int
	Path        string
	Command     []string
	Interval    int
	Timeout     int
	Retries     int
	StartPeriod int
}

func (*HealthCheck) Normalized

func (h *HealthCheck) Normalized() HealthCheck

type HealthCheckType

type HealthCheckType string
const (
	HealthCheckHTTP HealthCheckType = "http"
	HealthCheckTCP  HealthCheckType = "tcp"
	HealthCheckExec HealthCheckType = "exec"
)

type PortMapping

type PortMapping struct {
	ContainerPort int
	HostPort      int
	Protocol      network.IPProtocol
}

func PortMappingsFromPortMap

func PortMappingsFromPortMap(ports network.PortMap) []PortMapping

type Result

type Result string

type Security added in v0.1.1

type Security struct {
	// "uid", "uid:gid"
	User string

	// extra groups the container process belongs to
	GroupAdd []string

	// kernel capabilities
	CapAdd  []string
	CapDrop []string

	// mount an empty tmpfs at each path. "<path>:<options>"
	Tmpfs []string

	ReadOnlyRootfs  bool
	NoNewPrivileges bool
	Privileged      bool

	PidsLimit int64

	// per-resource rlimits for the container process, e.g. nofile
	Ulimits []Ulimit

	// "", "private", "shareable", "none" or "host"
	IpcMode string

	// re-map the container's UIDs through a user namespace
	UsernsMode string
}

mirrors compose's hardening-related options

type State

type State int
const (
	Pending State = iota
	Scheduled
	Running
	Completed
	Failed
)

func (State) String

func (s State) String() string

implementing fmt.Stringer

type Task

type Task struct {
	ID            uuid.UUID
	ContainerID   string
	Name          string
	State         State
	Image         string
	Cpu           float64
	Memory        int64
	Disk          int64
	Ports         []PortMapping
	Cmd           []string
	Env           []string
	RestartPolicy string
	HostPorts     []PortMapping // resolved bindings reported by the daemon

	HealthCheck     *HealthCheck
	Security        *Security `json:",omitempty"` // container hardening options
	RestartCount    int
	MaxRestarts     int    // per-task restart cap; 0 = fall back to manager.MaxRestarts
	FailureReason   string `json:",omitempty"`
	ManuallyStopped bool   `json:",omitempty"` // by user
	// earliest time the orchestrator will attempt the next restart
	// zero means immediately eligible
	NextRetryAt time.Time `json:",omitempty"`

	StartTime  time.Time
	FinishTime time.Time

	Timeout int64 // max seconds a task may run before the worker kills it, 0 = unlimited
}

func ResolveRef

func ResolveRef(tasks []Task, ref string) (match Task, found bool, ambiguous bool)

resolves a task reference (UUID or name) against a snapshot of tasks

func (Task) AtRestartCap

func (t Task) AtRestartCap(clusterMaxRestarts int) bool

func (Task) EffectiveMaxRestarts

func (t Task) EffectiveMaxRestarts(defaultMaxRestarts int) int

func (Task) IsTerminal

func (t Task) IsTerminal() bool

func (Task) Key

func (t Task) Key() uuid.UUID

func (Task) Validate added in v0.1.1

func (t Task) Validate() error

type TaskEvent

type TaskEvent struct {
	ID        uuid.UUID
	State     State
	Timestamp time.Time
	Task      Task
}

func (TaskEvent) Key

func (te TaskEvent) Key() uuid.UUID

type TaskLogs

type TaskLogs struct {
	TaskID     uuid.UUID
	ExitCode   *int   // nil if still running/unknown
	Logs       []byte // demultiplexed stdout+stderr, bounded at capture time
	CapturedAt time.Time
	Source     string // "exit" | "stop" | "unhealthy"
}

captured snapshot of a task's container output, stored on the worker so logs survive container removal

func (TaskLogs) Key

func (l TaskLogs) Key() uuid.UUID

type Ulimit added in v0.1.1

type Ulimit struct {
	Name string
	Soft int64
	Hard int64
}

a single ulimit entry for Security.Ulimits Soft/Hard of -1 means "unlimited"

Jump to

Keyboard shortcuts

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