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

batch

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package batch emulates AWS Batch over REST-JSON: compute environments, job queues, scheduling policies, job definitions and jobs. With a container engine every job attempt runs as a container (array jobs, dependencies, retries and timeouts included) and logs to CloudWatch Logs; without one, jobs wait in RUNNABLE.

Index

Constants

View Source
const NoDocker = "pogi: Docker is not available, so jobs cannot run"

NoDocker is the status reason of jobs that wait for a container engine.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array struct {
	Size    int            `json:"size,omitempty"`
	Index   *int           `json:"index,omitempty"`
	Summary map[string]int `json:"statusSummary,omitempty"`
}

Array is an array job's size and its children's statuses, or a child's index.

type Attempt

type Attempt struct {
	Container *Container `json:"container"`
	Started   int64      `json:"startedAt,omitempty"`
	Stopped   int64      `json:"stoppedAt,omitempty"`
	Reason    string     `json:"statusReason,omitempty"`
}

Attempt is how one try of a job ended.

type Container

type Container struct {
	Image         string   `json:"image,omitempty"`
	Command       []string `json:"command,omitempty"`
	Environment   []KV     `json:"environment,omitempty"`
	Vcpus         int      `json:"vcpus,omitempty"`
	Memory        int      `json:"memory,omitempty"`
	Resources     []Need   `json:"resourceRequirements,omitempty"`
	JobRole       string   `json:"jobRoleArn,omitempty"`
	ExecutionRole string   `json:"executionRoleArn,omitempty"`
	User          string   `json:"user,omitempty"`
	ExitCode      *int     `json:"exitCode,omitempty"`
	Reason        string   `json:"reason,omitempty"`
	LogStream     string   `json:"logStreamName,omitempty"`
}

Container is a job's container: its definition's container properties with the overrides applied, and how its last attempt ended.

type Def

type Def struct {
	Name          string            `json:"jobDefinitionName"`
	Arn           string            `json:"jobDefinitionArn"`
	Revision      int               `json:"revision"`
	Status        string            `json:"status"`
	Type          string            `json:"type"`
	Parameters    map[string]string `json:"parameters,omitempty"`
	Retry         *Retry            `json:"retryStrategy,omitempty"`
	Timeout       *Timeout          `json:"timeout,omitempty"`
	Container     json.RawMessage   `json:"containerProperties,omitempty"`
	Node          json.RawMessage   `json:"nodeProperties,omitempty"`
	Eks           json.RawMessage   `json:"eksProperties,omitempty"`
	Ecs           json.RawMessage   `json:"ecsProperties,omitempty"`
	Platform      []string          `json:"platformCapabilities,omitempty"`
	PropagateTags bool              `json:"propagateTags,omitempty"`
	Priority      *int              `json:"schedulingPriority,omitempty"`
	Tags          map[string]string `json:"tags,omitempty"`
}

Def is one revision of a job definition; its container, node, EKS and ECS properties are kept as given.

type Dep

type Dep struct {
	JobID string `json:"jobId,omitempty"`
	Type  string `json:"type,omitempty"`
}

Dep is a dependency: on a job, N_TO_N on an array job of the same size, or SEQUENTIAL among an array job's children.

type Env

type Env struct {
	Name          string            `json:"computeEnvironmentName"`
	Arn           string            `json:"computeEnvironmentArn"`
	Type          string            `json:"type"`
	State         string            `json:"state"`
	Status        string            `json:"status"`
	StatusReason  string            `json:"statusReason,omitempty"`
	Unmanaged     *int              `json:"unmanagedvCpus,omitempty"`
	Resources     map[string]any    `json:"computeResources,omitempty"`
	ServiceRole   string            `json:"serviceRole,omitempty"`
	UpdatePolicy  map[string]any    `json:"updatePolicy,omitempty"`
	Eks           map[string]any    `json:"eksConfiguration,omitempty"`
	Context       string            `json:"context,omitempty"`
	Cluster       string            `json:"ecsClusterArn,omitempty"`
	Orchestration string            `json:"containerOrchestrationType"`
	UUID          string            `json:"uuid"`
	Tags          map[string]string `json:"tags,omitempty"`
}

Env is a compute environment; its compute resources are kept as given.

type Job

type Job struct {
	ID            string            `json:"jobId"`
	Arn           string            `json:"jobArn"`
	Name          string            `json:"jobName"`
	Queue         string            `json:"jobQueue,omitempty"`
	Def           string            `json:"jobDefinition"`
	Status        string            `json:"status"`
	Reason        string            `json:"statusReason,omitempty"`
	Created       int64             `json:"createdAt"`
	Started       int64             `json:"startedAt,omitempty"`
	Stopped       int64             `json:"stoppedAt,omitempty"`
	Attempts      []Attempt         `json:"attempts,omitempty"`
	DependsOn     []Dep             `json:"dependsOn,omitempty"`
	Parameters    map[string]string `json:"parameters,omitempty"`
	Container     *Container        `json:"container,omitempty"`
	Array         *Array            `json:"arrayProperties,omitempty"`
	Retry         *Retry            `json:"retryStrategy,omitempty"`
	Timeout       *Timeout          `json:"timeout,omitempty"`
	Platform      []string          `json:"platformCapabilities,omitempty"`
	PropagateTags bool              `json:"propagateTags,omitempty"`
	Share         string            `json:"shareIdentifier,omitempty"`
	Priority      *int              `json:"schedulingPriority,omitempty"`
	Cancelled     bool              `json:"isCancelled,omitempty"`
	Terminated    bool              `json:"isTerminated,omitempty"`
	Tags          map[string]string `json:"tags,omitempty"`
	// contains filtered or unexported fields
}

Job is a job, an array job's parent or one of its children.

type KV

type KV struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

KV is an environment variable.

type Need

type Need struct {
	Type  string `json:"type"`
	Value string `json:"value"`
}

Need is a resource requirement: VCPU, MEMORY (MiB) or GPU.

type OnExit

type OnExit struct {
	Action         string `json:"action"`
	OnExitCode     string `json:"onExitCode,omitempty"`
	OnReason       string `json:"onReason,omitempty"`
	OnStatusReason string `json:"onStatusReason,omitempty"`
}

OnExit decides whether a failed attempt is retried.

type Order

type Order struct {
	Order int    `json:"order"`
	Env   string `json:"computeEnvironment"`
}

Order places a compute environment in a queue.

type Policy

type Policy struct {
	Name      string            `json:"name"`
	Arn       string            `json:"arn"`
	Fairshare map[string]any    `json:"fairsharePolicy,omitempty"`
	Tags      map[string]string `json:"tags,omitempty"`
}

Policy is a scheduling policy, kept as given.

type Queue

type Queue struct {
	Name         string            `json:"jobQueueName"`
	Arn          string            `json:"jobQueueArn"`
	State        string            `json:"state"`
	Status       string            `json:"status"`
	StatusReason string            `json:"statusReason,omitempty"`
	Priority     int               `json:"priority"`
	Order        []Order           `json:"computeEnvironmentOrder"`
	Policy       string            `json:"schedulingPolicyArn,omitempty"`
	TimeLimits   []any             `json:"jobStateTimeLimitActions,omitempty"`
	Tags         map[string]string `json:"tags,omitempty"`
}

Queue is a job queue.

type Retry

type Retry struct {
	Attempts int      `json:"attempts,omitempty"`
	OnExit   []OnExit `json:"evaluateOnExit,omitempty"`
}

Retry is a retry strategy.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the Batch emulator.

func New

func New(hub *core.Hub) *Service

New creates the Batch service.

func (*Service) Close

func (s *Service) Close() error

Close stops the scheduler and the attempts still running, removing their containers.

func (*Service) Info

func (s *Service) Info() core.Info

func (*Service) Inspect

func (s *Service) Inspect(table, id string) any

func (*Service) Load

func (s *Service) Load(b []byte) error

Load restores state; attempts that were running have lost their containers and fail.

func (*Service) Reset

func (s *Service) Reset()

func (*Service) Resources

func (s *Service) Resources() []core.Table

func (*Service) Save

func (s *Service) Save() ([]byte, error)

func (*Service) ServeHTTP

func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Service) Tick

func (s *Service) Tick(now time.Time)

Tick moves environments and queues to VALID (or away, once deleted) and jobs along: SUBMITTED, PENDING until their dependencies succeed, RUNNABLE until a container can start. Running attempts end on their own.

type Timeout

type Timeout struct {
	Seconds int `json:"attemptDurationSeconds,omitempty"`
}

Timeout limits each attempt.

Jump to

Keyboard shortcuts

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