jobdef

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package jobdef provides job definition utilities including collection and import of YAML manifests.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicateJob       = errors.New("job alias already exists")
	ErrProvenanceConflict = errors.New("job definition provenance conflict")
	ErrJobRunning         = errors.New("job has a running run")
	ErrContractBreak      = contractenforce.ErrContractBreakBlocked
	ErrContractAck        = contractenforce.ErrInvalidContractAck
)
View Source
var ErrTriggerChainCycle = errors.New("trigger chain cycle detected")

Functions

func CollectDefinitions

func CollectDefinitions(paths []string, validate bool) ([]schema.Definition, error)

CollectDefinitions walks the given paths, reads YAML files, and returns all valid Caesium job definitions found. Non-Caesium YAML documents (e.g. Helm charts, Kubernetes manifests) are silently skipped. If validate is true, each definition is validated and errors are returned.

func ContractBreakResponse

func ContractBreakResponse(err error) (any, bool)

ContractBreakResponse returns the stable 409 payload for an apply-time contract enforcement error.

func IsYAML

func IsYAML(path string) bool

IsYAML returns true if the file path has a .yaml or .yml extension.

func ResolveYAMLFiles

func ResolveYAMLFiles(paths []string) ([]string, error)

ResolveYAMLFiles returns all YAML file paths under the given paths.

func SetTriggerMutationHook

func SetTriggerMutationHook(hook TriggerMutationHook)

func ValidateAgentProfileRefs

func ValidateAgentProfileRefs(ctx context.Context, conn *gorm.DB, defs []schema.Definition) error

ValidateAgentProfileRefs verifies that every server-side resource a metadata.remediation block references exists: the AgentProfile named by remediation.profile and the NotificationChannel named by remediation.escalation.channel. This is the server-side half of the lint split docs/design-agent-in-the-loop.md documents: pkg/jobdef's offline validation (which runs with conn == nil, e.g. `caesium job lint`) can only check the references are well-formed and emits a scope note, because these are server-side state. This function closes that gap and is invoked both from POST /v1/jobdefs/lint and from Importer.ValidateBatch inside the apply transaction, mirroring ValidateDatasetGraph's conn-may-be-nil posture.

The built-in models.DefaultTriageOnlyProfileName is treated as always resolvable regardless of DB state: it is the shipped default jobs are advertised to reference, seeded lazily/idempotently — so a job referencing it must never be rejected merely because the row has not been materialized on this particular server yet.

func ValidateDatasetGraph

func ValidateDatasetGraph(ctx context.Context, conn *gorm.DB, defs []schema.Definition) error

ValidateDatasetGraph runs the cross-job declared-graph lint over the incoming definitions PLUS the persisted declarations of jobs that are not being replaced: exactly one job produces a given dataset, every consumed dataset resolves to a produced dataset or a declared source across the whole set, and the declared graph is acyclic across jobs. It is the batch counterpart to the per-definition dataset validation in pkg/jobdef (which sees one job at a time and cannot prove a cross-job cycle or a duplicate producer).

conn may be nil (e.g. `caesium job lint` with no server), in which case only the incoming set is checked. The pure graph algorithm lives in internal/freshness so it is unit-testable without a database.

func ValidateTriggerChains

func ValidateTriggerChains(ctx context.Context, conn *gorm.DB, defs []schema.Definition) error

Types

type ApplyOptions

type ApplyOptions struct {
	Provenance       *Provenance
	Force            bool
	ContractAck      *contractenforce.AllowBreaking
	ContractWarnings *[]contractenforce.ContractWarning
}

ApplyOptions control optional behaviors for ApplyWithOptions.

type Importer

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

Importer coordinates persistence of job definitions.

func NewImporter

func NewImporter(dbConn *gorm.DB) *Importer

NewImporter creates a new importer. The provided db connection must be non-nil.

func (*Importer) Apply

func (i *Importer) Apply(ctx context.Context, def *schema.Definition) (*models.Job, error)

Apply persists the provided definition and returns the reconciled job record.

func (*Importer) ApplyWithOptions

func (i *Importer) ApplyWithOptions(ctx context.Context, def *schema.Definition, opts *ApplyOptions) (*models.Job, error)

ApplyWithOptions persists the provided definition using the supplied options. Existing jobs are reconciled in place so history remains attached to the same job ID.

func (*Importer) PruneMissing

func (i *Importer) PruneMissing(ctx context.Context, desiredAliases []string, opts *PruneOptions) (int, error)

PruneMissing retires active jobs that are absent from the desired alias set. When opts.SourceID is set, pruning is scoped to jobs imported by that source.

func (*Importer) ValidateBatch

func (i *Importer) ValidateBatch(ctx context.Context, defs []schema.Definition) error

type Provenance

type Provenance struct {
	SourceID string
	Repo     string
	Ref      string
	Commit   string
	Path     string
}

Provenance captures metadata describing the origin of a job definition.

type PruneOptions

type PruneOptions struct {
	SourceID string
}

PruneOptions scope the set of jobs that should be retired when pruning.

type SnapshotQuery

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

SnapshotQuery provides read-only access to dag_snapshot rows. It does not touch the write path (writeSnapshotTx in importer.go). ctx is propagated to every query via db.WithContext so that request cancellation and deadlines are honoured — matching the house pattern used by other services (trigger, notification, etc.).

func NewSnapshotQuery

func NewSnapshotQuery(ctx context.Context, conn *gorm.DB) *SnapshotQuery

NewSnapshotQuery returns a SnapshotQuery backed by conn.

func (*SnapshotQuery) ByContentHash

func (q *SnapshotQuery) ByContentHash(jobID uuid.UUID, contentHash string) (*models.DagSnapshot, error)

ByContentHash returns the snapshot matching jobID + contentHash, or gorm.ErrRecordNotFound when none matches.

func (*SnapshotQuery) ByGitCommit

func (q *SnapshotQuery) ByGitCommit(jobID uuid.UUID, commit string) (*models.DagSnapshot, error)

ByGitCommit returns the most-recent snapshot for jobID whose git_commit matches commit, or gorm.ErrRecordNotFound when none matches.

func (*SnapshotQuery) Latest

func (q *SnapshotQuery) Latest(jobID uuid.UUID) (*models.DagSnapshot, error)

Latest returns the most-recently written snapshot for jobID, or gorm.ErrRecordNotFound when no snapshot exists.

func (*SnapshotQuery) List

func (q *SnapshotQuery) List(jobID uuid.UUID) ([]models.DagSnapshot, error)

List returns all snapshots for jobID ordered by created_at descending (newest first).

type TriggerMutationHook

type TriggerMutationHook func(context.Context) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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