lifecycle

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package lifecycle defines the controller's view of a job's phases and the rules that move a job between them. It is deliberately small: the jobagent inside each container owns the fine-grained execution state; the controller only needs a coarse phase per run plus a restart policy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanTransition

func CanTransition(from, to Phase) bool

CanTransition reports whether from → to is a legal edge.

Types

type Phase

type Phase string

Phase is the controller-level state of a run. It is a superset of the jobagent phases: the controller adds Submitted (accepted but not yet launched) and Cancelled (a user-requested stop, distinct from a job that finished on its own).

const (
	Submitted  Phase = "submitted"
	Starting   Phase = "starting"
	Running    Phase = "running"
	Cancelling Phase = "cancelling"
	Cancelled  Phase = "cancelled"
	Finished   Phase = "finished"
	Failed     Phase = "failed"
)

func FromAgent

func FromAgent(agentPhase string) Phase

FromAgent maps a jobagent phase string to a controller Phase. Unknown values map to Failed so a garbled report never looks healthy.

func (Phase) Terminal

func (p Phase) Terminal() bool

Terminal reports whether the phase is an end state (no container is or should be running).

type RestartPolicy

type RestartPolicy struct {
	MaxAttempts int           // 0 disables automatic restart
	BaseBackoff time.Duration // backoff = BaseBackoff * 2^(attempt-1), capped
	MaxBackoff  time.Duration
}

RestartPolicy bounds automatic restarts of a job whose desired state is running but whose container exited unexpectedly.

func DefaultRestartPolicy

func DefaultRestartPolicy() RestartPolicy

DefaultRestartPolicy is a conservative default: a few tries with exponential backoff.

func (RestartPolicy) Backoff

func (p RestartPolicy) Backoff(attempt int) time.Duration

Backoff returns how long to wait before the given attempt number (1-based). Exponential, capped at MaxBackoff.

func (RestartPolicy) ShouldRestart

func (p RestartPolicy) ShouldRestart(phase Phase, attempt int) bool

ShouldRestart reports whether a run that just reached `phase` on its `attempt` should be restarted. Only unexpected failures restart; a clean Finished or a user Cancelled does not.

Jump to

Keyboard shortcuts

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