job

package
v0.0.0-...-ca91bd3 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package job is the common types and machinery for survey jobs.

Index

Constants

This section is empty.

Variables

View Source
var CacheDir string

CacheDir is a precreated directory that Jobs can cache files underneath.

Functions

func Available

func Available() []string

Available reports the names of known Jobs.

func Defaults

func Defaults() []string

Defaults reports the names of the default-enabled Jobs.

func Register

func Register(j Job, enable bool)

Register registers a Job to run and marks it to be default enabled or not.

func StoreError

func StoreError(err error) error

StoreError marks the error returned from an Analyzer as one that should be recorded as a result and not stop the run.

Types

type Analyzer

type Analyzer interface {
	// Analyze is called for every layer that was selected by a LayerSelector.
	//
	// "Contents" will be populated if the LayerSelector reported true for the
	// "load" boolean.
	Analyze(ctx context.Context, contents io.Reader) (record any, err error)
	Close() error
}

Analyzer does analysis on selected layers.

type Job

type Job interface {
	// Name is the unique name for this job.
	//
	// Registration will panic if the name is not unique.
	// The reported name must be stable.
	Name() string
	// Record is an instance of the type that the Analyzer and Reporter
	// implementations returned by this Job will use.
	//
	// Must be a pointer to a struct.
	Record() any
	// Close frees any held resources.
	Close() error

	// SelectImage returns a LayerSelector for a given image.
	//
	// The returned object must be an independent instance.
	SelectImage(ctx context.Context, image string) LayerSelector
	// Analyzer returns an Analyzer instance.
	//
	// The returned object must be an independent instance.
	Analyzer() (Analyzer, error)
	// Reporter returns a Reporter instance.
	Reporter() (Reporter, error)
}

Job describes a single survey job.

func Jobs

func Jobs(ns []string) ([]Job, error)

Jobs returns the named Jobs.

type LayerSelector

type LayerSelector interface {
	SelectLayer(context.Context, digest.Digest, *tar.Header) (hit, load bool, err error)
	Close() error
}

LayerSelector is called for each layer on a given image, with the tar header of every file in that layer.

Once a "hit" is reported, SelectLayer will stop being called.

type Reporter

type Reporter interface {
	Begin(ctx context.Context, w io.Writer) error
	Record(ctx context.Context, w io.Writer, layer string, pos int, record any, err error) error
	End(ctx context.Context, w io.Writer) error
}

Reporter writes out reports.

By convention, any headers, footers, or comments start with "#" and the output is in tab-separated value format.

The "Begin" and "End" methods work like the awk "BEGIN" and "END" actions.

type StoredError

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

StoredError is the concrete type for StoreError.

Job implementations should not need to care about this.

func (*StoredError) Error

func (e *StoredError) Error() string

Error implements error.

func (*StoredError) Unwrap

func (e *StoredError) Unwrap() error

Unwrap implements error.

Directories

Path Synopsis
Package repoid implements a survey job reporting on the dnf repositories recorded in Red Hat containers.
Package repoid implements a survey job reporting on the dnf repositories recorded in Red Hat containers.

Jump to

Keyboard shortcuts

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