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

job

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package job provides the Job[T] type: a discoverer-backed, parallelised, optionally-retried unit of work implementing interfaces.AnyJob.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Adapt

Adapt lifts a runner-less Runnable into an AnyJob for gate composition, so callers compose typed Runnables instead of threading a nil CommandRunner.

func FilterByLang

func FilterByLang(jobs []TaggedJob, goFlag, pyFlag, tsFlag bool) []interfaces.AnyJob

FilterByLang returns the jobs whose LangTag matches the enabled flags. LangInfra jobs are always included - they validate shared infrastructure (Docker, k8s, proto) that must pass regardless of which language changed.

func Single

func Single(
	name, group string,
	tool interfaces.ToolSpec,
	argsFn func(root string) []string,
	dirFn func(root string) string,
	opts ...Option,
) interfaces.AnyJob

Single creates a Job[string] that runs exactly one command. tool.Cmd overrides the executable prefix when set (e.g. ["uv", "run", "ruff"]).

Types

type Builder

type Builder[T any] struct {
	// contains filtered or unexported fields
}

Builder[T] assembles a Job[T] via a fluent API. Field order minimises GC pointer-scan range: interfaces, func, strings, slices.

func New

func New[T any](name, group string) *Builder[T]

New returns a Builder[T] for a job with the given name and group.

func (*Builder[T]) Build

func (b *Builder[T]) Build() interfaces.AnyJob

Build constructs and returns the Job[T].

func (*Builder[T]) WithDiscoverer

func (b *Builder[T]) WithDiscoverer(d interfaces.Discoverer[T]) *Builder[T]

WithDiscoverer sets the Discoverer that yields work items.

func (*Builder[T]) WithMapper

func (b *Builder[T]) WithMapper(
	fn func(root string, item T) engine.WorkUnit,
) *Builder[T]

WithMapper sets the function that converts (root, item) into a WorkUnit.

func (*Builder[T]) WithOptions

func (b *Builder[T]) WithOptions(opts ...Option) *Builder[T]

WithOptions appends execution options.

func (*Builder[T]) WithTool

func (b *Builder[T]) WithTool(t interfaces.ToolSpec) *Builder[T]

WithTool sets the ToolSpec checked by RequireTool before execution.

type Conditional

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

Conditional wraps an AnyJob and runs it only when condition returns true. When the condition is false the job returns a single Skip result.

func When

func When(
	job interfaces.AnyJob,
	condition func(ctx context.Context, root string) bool,
) *Conditional

When wraps job with a condition; the job runs only when condition returns true.

func (*Conditional) Execute

func (c *Conditional) Execute(
	ctx context.Context,
	runner interfaces.CommandRunner,
	root string,
) (types.StepResults, error)

Execute implements interfaces.AnyJob.

func (*Conditional) Meta

func (c *Conditional) Meta() types.JobMeta

Meta implements interfaces.AnyJob.

type Job

type Job[T any] struct {
	// contains filtered or unexported fields
}

Job[T] discovers work items of type T, maps each to a WorkUnit, and fans them out in parallel. It implements interfaces.AnyJob. Field order minimises GC pointer-scan range: interfaces, func, strings, value types.

func (*Job[T]) Execute

func (j *Job[T]) Execute(
	ctx context.Context,
	runner interfaces.CommandRunner,
	root string,
) (types.StepResults, error)

Execute implements interfaces.AnyJob. It checks the required tool (skip if missing), discovers items (skip if none), maps each to a WorkUnit, fans them out via FanOut, then optionally downgrades failures to warnings when WarnOnly is set.

func (*Job[T]) Meta

func (j *Job[T]) Meta() types.JobMeta

Meta implements interfaces.AnyJob.

type JobConfig

type JobConfig struct {
	// Concurrency is the max number of parallel workers; 0 means runtime.NumCPU.
	Concurrency int

	// Retry is the max number of retry attempts after a step failure (0 = no retry).
	Retry int

	// RetryDelay is the pause between retry attempts.
	RetryDelay time.Duration

	// WarnOnly downgrades Fail results to Warn so the job never blocks a gate.
	WarnOnly bool
}

JobConfig holds execution parameters applied to every step in the job.

type LangTag

type LangTag string

LangTag identifies which language stack a job belongs to.

const (
	// LangGo tags jobs that belong to the Go stack.
	LangGo LangTag = "go"

	// LangPython tags jobs that belong to the Python stack.
	LangPython LangTag = "python"

	// LangTS tags jobs that belong to the TypeScript stack.
	LangTS LangTag = "ts"

	// LangInfra covers Docker, k8s, proto, and shellcheck jobs that must run
	// regardless of which language-specific flags are set.
	LangInfra LangTag = "infra"
)

type Option

type Option func(*JobConfig)

Option configures a JobConfig.

func WithConcurrency

func WithConcurrency(n int) Option

WithConcurrency sets the maximum number of parallel workers.

func WithRetry

func WithRetry(n int) Option

WithRetry sets the maximum number of retry attempts on step failure.

func WithRetryDelay

func WithRetryDelay(
	d time.Duration,
) Option

WithRetryDelay sets the pause between retry attempts.

func WithWarnOnly

func WithWarnOnly() Option

WithWarnOnly marks the job non-blocking: Fail results are downgraded to Warn.

type TaggedJob

type TaggedJob struct {
	// AnyJob is the embedded job being tagged; its methods are promoted.
	interfaces.AnyJob

	// Lang is the language stack this job belongs to, used by FilterByLang.
	Lang LangTag
}

TaggedJob pairs an AnyJob with its language tag.

func Tag

func Tag(lang LangTag, j interfaces.AnyJob) TaggedJob

Tag wraps j with a language tag.

Directories

Path Synopsis
Package decorators provides logging, metrics, tracing, and recovery wrappers for interfaces.AnyJob.
Package decorators provides logging, metrics, tracing, and recovery wrappers for interfaces.AnyJob.

Jump to

Keyboard shortcuts

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