amboy: github.com/mongodb/amboy/dependency Index | Files

package dependency

import "github.com/mongodb/amboy/dependency"

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 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.

Index

Package Files

always.go creates.go edges.go local.go manager.go mock.go state.go state_string.go types.go

Constants

const (
    // AlwaysRun dependencies are tasks that *always* run.
    AlwaysRun = "always"

    // Create dependencies run only if a file does *not* exist.
    Create = "create-file"

    // LocalFileRelationship dependencies compare a list of
    // targets and dependencies and run if any target is older
    // than any dependency, like make.
    LocalFileRelationship = "local-file"
)

These values provide consistent ways of referring to the type names for dependencies.

func IsValidState Uses

func IsValidState(s State) bool

IsValidState checks states and ensures that a state is valid.

type Always Uses

type Always struct {
    ShouldRebuild bool     `json:"should_rebuild" bson:"should_rebuild" yaml:"should_rebuild"`
    T             TypeInfo `json:"type" bson:"type" yaml:"type"`
    *JobEdges
}

Always is a DependencyManager implementation that always reports that the task is ready to run.

func NewAlways Uses

func NewAlways() *Always

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

func (*Always) State Uses

func (d *Always) State() State

State always returns, for Always, the "Ready" state.

func (*Always) Type Uses

func (d *Always) Type() TypeInfo

Type returns a DependencyInterchange object to assist in unmarshalling dependency objects.

type CreatesFile Uses

type CreatesFile struct {
    FileName string   `bson:"file_name" json:"file_name" yaml:"file_name"`
    T        TypeInfo `bson:"type" json:"type" yaml:"type"`

    *JobEdges
}

CreatesFile describes a task that is only ready to run if a specific file doesn't exist. Specify that file as the FileName attribute, or to the NewCreatesFile constructor.

func NewCreatesFile Uses

func NewCreatesFile(name string) *CreatesFile

NewCreatesFile constructs a CreatesFile object in cases when the dependent FileName is known at object creation time.

func NewCreatesFileInstance Uses

func NewCreatesFileInstance() *CreatesFile

NewCreatesFileInstance builds a new CreatesFile object, used in the factory function for the registry, and for cases when the dependent file is not known at construction time.

func (*CreatesFile) State Uses

func (d *CreatesFile) State() State

State returns Ready if the dependent file does not exist or is not specified, and Passed if the file *does* exist. Jobs with Ready states should be executed, while those with Passed states should be a no-op.

func (*CreatesFile) Type Uses

func (d *CreatesFile) Type() TypeInfo

Type returns the type information on the "creates-file" Manager implementation.

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"`
    *JobEdges
}

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 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 NewLocalFileInstance Uses

func NewLocalFileInstance() *LocalFile

NewLocalFileInstance is a constructor that returns an initialized LocalFile object, and can be used instead of NewLocalFile when the targets and dependencies are not known at construction time.

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.

type MockDependency Uses

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 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.
    Passed

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

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

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 3 packages (graph) and is imported by 12 packages. Updated 2017-03-30. Refresh now. Tools for package owners.