amboy: Index | Files

package dependency

import ""

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


Dependencies have methods to add or access Edges of the task. 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 tasks to express their dependencies on other tasks as a hint to Queue implementations. Separately, queue implementation checks the environment to ensure that all prerequisites are satisfied.


Package Files

always.go callback.go creates.go edges.go local.go manager.go mock.go registry.go state.go state_string.go

func IsValidState Uses

func IsValidState(s State) bool

IsValidState checks states and ensures that a state is valid.

func RegisterCheck Uses

func RegisterCheck(name string, f CheckFactory)

RegisterCheck stores a CheckFactory in the global check registry.

func RegisterManager Uses

func RegisterManager(name string, f ManagerFactory)

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

type CheckFactory Uses

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 Uses

func GetCheckFactory(name string) (CheckFactory, error)

GetCheckFactory returns a globally registered check factory by name.

type CheckFunc Uses

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 Uses

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 Uses

func NewJobEdges() JobEdges

NewJobEdges returns an initialized JobEdges object.

func (*JobEdges) AddEdge Uses

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 Uses

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 Uses

type LocalFile struct {
    // A list of file names that the task 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"`

LocalFile describes a dependency between a task 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 (task names) for other amboy.Job IDs in the queue if you need to express that kind of relationship.

func MakeLocalFile Uses

func MakeLocalFile() *LocalFile

MakeLocalFile constructs an empty local file instance.

func NewLocalFile Uses

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 Uses

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 Uses

func (d *LocalFile) Type() TypeInfo

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

type Manager Uses

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

    // Computes and returns a list of Job IDs that this task
    // 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 Uses

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 Uses

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 Uses

func NewCreatesFile(name string) Manager

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

type ManagerFactory Uses

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 Uses

func GetManagerFactory(name string) (ManagerFactory, error)

GetManagerFactory returns a globally registered manager factory by name.

type MockDependency Uses

type MockDependency struct {
    Response State
    T        TypeInfo

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

func NewMock Uses

func NewMock() *MockDependency

NewMock constructs a new mocked dependency object.

func (*MockDependency) State Uses

func (d *MockDependency) State() State

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

func (*MockDependency) Type Uses

func (d *MockDependency) Type() TypeInfo

Type returns the TypeInfo value for this dependency implementation.

type State Uses

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 task's dependencies

const (
    // Ready indicates that a task 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.

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

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

func (State) String Uses

func (i State) String() string

type TypeInfo Uses

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.

Package dependency imports 5 packages (graph) and is imported by 27 packages. Updated 2019-05-18. Refresh now. Tools for package owners.