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

package job

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

Package job provides tools and generic implementations of jobs for amboy Queues.

Base Metadata

The Base type provides an implementation of the amboy.Job interface that does *not* have a Run method, and can be embedded in your own job implementations to avoid implemented duplicated common functionality. The type also implements several methods which are not part of the Job interface for error handling (e.g. AddError and HasErrors), and methods for marking tasks complete and setting the ID (e.g. MarkComplete and SetID).

All job implementations should use this functionality, although there are some situations where jobs may want independent implementation of the Job interface, including: easier construction for use from the REST interface, needing or wanting a more constrained public interface, or needing more constrained options for some values (e.g. Dependency, Priority).

Index

Package Files

base.go counter.go group.go init.go shell.go

func GetNumber Uses

func GetNumber() int

GetNumber is a source of safe monotonically increasing integers for use in Job ids.

func RegisterDefaultJobs Uses

func RegisterDefaultJobs()

RegisterDefaultJobs registers all default job types in the amboy Job registry which permits their use in contexts that require serializing jobs to or from a common format (e.g. queues that persist pending and completed jobs outside of the process,) or the REST interface.

In most applications these registrations happen automatically in the context of package init() functions, but for the default/generic jobs, users must explicitly load them into the registry.

type Base Uses

type Base struct {
    TaskID        string        `bson:"name" json:"name" yaml:"name"`
    JobType       amboy.JobType `bson:"job_type" json:"job_type" yaml:"job_type"`
    Errors        []string      `bson:"errors" json:"errors" yaml:"errors"`
    PriorityValue int           `bson:"priority" json:"priority" yaml:"priority"`
    // contains filtered or unexported fields
}

Base is a type that all new checks should compose, and provides an implementation of most common Job methods which most jobs need not implement themselves.

func (*Base) AddError Uses

func (b *Base) AddError(err error)

AddError takes an error object and if it is non-nil, tracks it internally. This operation is thread safe, but not part of the Job interface.

func (*Base) Dependency Uses

func (b *Base) Dependency() dependency.Manager

Dependency returns an amboy Job dependency interface object, and is a component of the Job interface.

func (*Base) Error Uses

func (b *Base) Error() error

Error returns all of the error objects produced by the job.

func (*Base) HasErrors Uses

func (b *Base) HasErrors() bool

HasErrors checks the stored errors in the object and reports if there are any stored errors. This operation is thread safe, but not part of the Job interface.

func (*Base) ID Uses

func (b *Base) ID() string

ID returns the name of the job, and is a component of the Job interface.

func (*Base) MarkComplete Uses

func (b *Base) MarkComplete()

MarkComplete signals that the job is complete, and is not part of the Job interface.

func (*Base) Priority Uses

func (b *Base) Priority() int

Priority returns the priority value, and is part of the amboy.Job interface.

func (*Base) SetDependency Uses

func (b *Base) SetDependency(d dependency.Manager)

SetDependency allows you to inject a different Job dependency object, and is a component of the Job interface.

func (*Base) SetID Uses

func (b *Base) SetID(n string)

SetID makes it possible to change the ID of an amboy.Job. It is not part of the amboy.Job interface.

func (*Base) SetPriority Uses

func (b *Base) SetPriority(p int)

SetPriority allows users to set the priority of a job, and is part of the amboy.Job interface.

func (*Base) SetStatus Uses

func (b *Base) SetStatus(s amboy.JobStatusInfo)

SetStatus resets the Status object of a Job document without. It is part of the Job interface and used by remote queues.

func (*Base) Status Uses

func (b *Base) Status() amboy.JobStatusInfo

Status returns the current state of the job including information useful for locking for compatibility with remote queues that require managing exclusive access to a job.

func (*Base) Type Uses

func (b *Base) Type() amboy.JobType

Type returns the JobType specification for this object, and is a component of the Job interface.

type Group Uses

type Group struct {
    Jobs  map[string]*registry.JobInterchange `bson:"jobs" json:"jobs" yaml:"jobs"`
    *Base `bson:"metadata" json:"metadata" yaml:"metadata"`
    // contains filtered or unexported fields
}

Group is a structure for running collections of Job objects at the same time, as a single Job. Use Groups to isolate several Jobs from other Jobs in the queue, and ensure that several Jobs run on a single system.

func NewGroup Uses

func NewGroup(name string) *Group

NewGroup creates a new, empty Group object.

func (*Group) Add Uses

func (g *Group) Add(j amboy.Job) error

Add is not part of the Job interface, but allows callers to append jobs to the Group. Returns an error if a job with the same ID() value already exists in the group.

func (*Group) Run Uses

func (g *Group) Run()

Run executes the jobs. Provides "continue on error" semantics for Jobs in the Group. Returns an error if: the Group has already run, or if any of the constituent Jobs produce an error *or* if there are problems with the JobInterchange converters.

func (*Group) SetDependency Uses

func (g *Group) SetDependency(d dependency.Manager)

SetDependency allows you to configure the dependency.Manager instance for this object. If you want to swap different dependency instances you can as long as the new instance is of the "Always" type.

type ShellJob Uses

type ShellJob struct {
    Command    string            `bson:"command" json:"command" yaml:"command"`
    Output     string            `bson:"output" json:"output" yaml:"output"`
    WorkingDir string            `bson:"working_dir" json:"working_dir" yaml:"working_dir"`
    Env        map[string]string `bson:"env" json:"env" yaml:"env"`

    *Base `bson:"job_base" json:"job_base" yaml:"job_base"`
    sync.RWMutex
}

ShellJob is an amboy.Job implementation that runs shell commands in the context of an amboy.Job object.

func NewShellJob Uses

func NewShellJob(cmd string, creates string) *ShellJob

NewShellJob takes the command, as a string along with the name of a file that the command would create, and returns a pointer to a ShellJob object. If the "creates" argument is an empty string then the command always runs, otherwise only if the file specified does not exist. You can change the dependency with the SetDependency argument.

func NewShellJobInstance Uses

func NewShellJobInstance() *ShellJob

NewShellJobInstance returns a pointer to an initialized ShellJob instance, but does not set the command or the name. Use when the command is not known at creation time.

func (*ShellJob) Run Uses

func (j *ShellJob) Run()

Run executes the shell commands. Add keys to the Env map to modify the environment, or change the value of the WorkingDir property to set the working directory for this command. Captures output into the Output attribute, and returns the error value of the command.

Package job imports 10 packages (graph) and is imported by 11 packages. Updated 2017-11-20. Refresh now. Tools for package owners.