dependency

package
v0.0.0-...-dec677a Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: Apache-2.0 Imports: 5 Imported by: 20

Documentation

Overview

Package dependency contains the Manager interface, along with several implementations for different kinds of dependency checks.

Edges

Dependencies have methods to add or access Edges of the job. These allow Jobs, by way of their dependencies to express relationships between Jobs. Fundamentally managing Job ordering is a property of a Queue implementation, but these methods allow jobs to express their dependencies on other jobs as a hint to Queue implementations. Separately, queue implementation checks the environment to ensure that all prerequisites are satisfied.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidState

func IsValidState(s State) bool

IsValidState checks states and ensures that a state is valid.

func RegisterCheck

func RegisterCheck(name string, f CheckFactory)

RegisterCheck stores a CheckFactory in the global check registry.

func RegisterManager

func RegisterManager(name string, f ManagerFactory)

RegisterManager stores a dependency Manager factory in the global Manager registry.

Types

type CheckFactory

type CheckFactory func() CheckFunc

CheckFactory is a function that takes no arguments and returns a dependency callback for use in callback-style dependencies.

func GetCheckFactory

func GetCheckFactory(name string) (CheckFactory, error)

GetCheckFactory returns a globally registered check factory by name.

type CheckFunc

type CheckFunc func([]string) State

CheckFunc describes a function type that can be registered and used with the CheckManager. These functions are called by the dependency manager and passed a list of edges for this job, and should return.

In effect this makes it easy to write many plugable custom dependency manager, without needing to implement a large number of types.

type JobEdges

type JobEdges struct {
	TaskEdges []string `bson:"edges" json:"edges" yaml:"edges"`
	// contains filtered or unexported fields
}

JobEdges provides a common subset of a non-trivial Manager implementation. These objects provide two methods of the Manager interface, and keep track of the relationships between Jobs in a job queue.

func NewJobEdges

func NewJobEdges() JobEdges

NewJobEdges returns an initialized JobEdges object.

func (*JobEdges) AddEdge

func (e *JobEdges) AddEdge(name string) error

AddEdge adds an edge to the dependency tracker. If the edge already exists, this operation returns an error.

func (*JobEdges) Edges

func (e *JobEdges) Edges() []string

Edges returns a copy of JobEdges.Edges list of edges for this slice. As a result, adding or removing items from this slice does not affect other readers, and this object *only* reflects changes to the dependencies made after calling this method.

type LocalFile

type LocalFile struct {
	// A list of file names that the job would in theory create.
	Targets []string `bson:"targets" json:"targets" yaml:"targets"`

	// A list of file names that represent dependencies that the
	// Target depends on.
	Dependencies []string `bson:"dependencies" json:"dependencies" yaml:"dependencies"`

	T TypeInfo `bson:"type" json:"type" yaml:"type"`
	JobEdges
}

LocalFile describes a dependency between a job and local files. Has a notion of targets, and dependencies, and a la make dependency resolution returns state Passed (e.g. noop) if the target or targets are all newer than the dependency or dependencies. LocalFile will return state Ready in ambiguous cases where targets or dependencies are missing.

Importantly, the edges, which amboy Jobs and Queue should always assume are *not* files, are distinct from the Targets and Dependencies in the context of this dependency.Manager. Add edges (job names) for other amboy.Job IDs in the queue if you need to express that kind of relationship.

func MakeLocalFile

func MakeLocalFile() *LocalFile

MakeLocalFile constructs an empty local file instance.

func NewLocalFile

func NewLocalFile(target string, dependencies ...string) *LocalFile

NewLocalFile creates a dependency object that checks if dependencies on the local file system are created. This constructor takes, as arguments, a target name and a variable number of successive arguments that are dependencies. All arguments should be file names, relative to the working directory of the program.

func (*LocalFile) State

func (d *LocalFile) State() State

State reports if the dependency is satisfied. If the targets or are not specified *or* the file names of any target do not exist, then State returns Ready. If a dependency does not exist, This call will log a a warning.

Otherwise, If any dependency has a modification time that is after the earliest modification time of the targets, then State returns Ready. When all targets were modified after all of the dependencies, then State returns Passed.

func (*LocalFile) Type

func (d *LocalFile) Type() TypeInfo

Type returns a TypeInfo object for the Dependency object. Used by the registry and interchange systems.

type Manager

type Manager interface {
	// Reports the state of the dependency, and allows calling
	// jobs to determine if the dependencies for a Job have been
	// satisfied.
	State() State

	// Computes and returns a list of Job IDs that this job
	// depends on. While the State() method is ultimately
	// responsible for determining if a Dependency is resolved,
	// the Edges() function provides Queue implementations with a
	// way of (potentially) dependencies.
	Edges() []string

	// Adds new edges to the dependency manager.
	AddEdge(string) error

	// Returns a pointer to a DependencyType object, which is used
	// for serializing Dependency objects, when needed.
	Type() TypeInfo
}

Manager objects provide a way for Jobs and queues to communicate about dependencies between multiple Jobs. While some, indeed many Job implementations, will have dependencies that *always* trigger rebuilds, others will be able to specify a dependency that a queue implementation can use to order Jobs.

func NewAlways

func NewAlways() Manager

NewAlways creates a DependencyManager object that always returns the "Ready" indicating that all dependency requirements are met and that the target is required.

func NewCheckManager

func NewCheckManager(name string) Manager

NewCheckManager creates a new check manager that will call the registered Check function matching that name. If no such function exists, then the manager is Unresolved.

func NewCreatesFile

func NewCreatesFile(name string) Manager

NewCreatesFile constructs a dependency manager object to support jobs that are ready to run if a specific file doesn't exist.

type ManagerFactory

type ManagerFactory func() Manager

ManagerFactory is a function that takes no arguments and returns a dependency.Manager interface. When implementing a new dependency type, also register a factory function with the DependencyFactory signature to facilitate serialization.

func GetManagerFactory

func GetManagerFactory(name string) (ManagerFactory, error)

GetManagerFactory returns a globally registered manager factory by name.

type MockDependency

type MockDependency struct {
	Response State
	T        TypeInfo
	JobEdges
}

MockDependency implements the dependency.Manager interface, but provides the capability to mock out the behavior of the State() method.

func NewMock

func NewMock() *MockDependency

NewMock constructs a new mocked dependency object.

func (*MockDependency) State

func (d *MockDependency) State() State

State returns a state value derived from the Response field in the MockDependency struct.

func (*MockDependency) Type

func (d *MockDependency) Type() TypeInfo

Type returns the TypeInfo value for this dependency implementation.

type State

type State int

State provides a consistent set of values for DependencyManager implementations to use to report their state, and provide Queues and Jobs with a common set of terms to describe the state of a job's dependencies

const (
	// Ready indicates that a job is safe to execute from the
	// perspective of the Dependency Manager.
	Ready State = iota

	// Passed indicates that there is no work to be done for this
	// dependency.
	Passed

	// Blocked job are waiting for their dependencies to be
	// resolved.
	Blocked

	// Unresolved states are for cyclic dependencies or cases
	// where jobs depend on resources that cannot be built.
	Unresolved
)

func (State) String

func (i State) String() string

type TypeInfo

type TypeInfo struct {
	Name    string `json:"name" bson:"name" yaml:"name"`
	Version int    `json:"version" bson:"version" yaml:"version"`
}

TypeInfo describes the type information that every dependency implementation should provide in its Type() implementation.

Jump to

Keyboard shortcuts

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