amboy: Index | Files

package registry

import ""

Package registry contains infrastructure to support the persistence of Job definitions.

Job and Dependency Registries

Systems need to be able to create and access Jobs and Dependency instances potentially from other implementations, and the registry provides a way to register new Job types both internal and external to the amboy package, and ensures that Jobs can be persiststed and handled generically as needed.

When you implement a new amboy/dependency.Manager or amboy.Job type, be sure to write a simple factory function for the type and register the factory in an init() function. Consider the following example:

func init() {
   RegisterJobType("noop", noopJobFactory)

func noopJobFactory() amboy.Job {
   return &NoopJob{}  /

The dependency and job registers have similar interfaces.

The registry package also provides functions for converting between an "interchange" format for persisting Job objects of mixed types consistently. Typically only authors of Queue implementations will need to use these operations.


Package Files

dependency.go docs.go formats.go init.go interchange.go job.go raw.go registry.go

func AddCheckType Uses

func AddCheckType(name string, f dependency.CheckFactory)

AddCheckType registers a callback function used in the production of some dependencies

func AddDependencyType Uses

func AddDependencyType(name string, f dependency.ManagerFactory)

AddDependencyType registers a new dependency.Manager factories.

func AddJobType Uses

func AddJobType(name string, f JobFactory)

AddJobType adds a job type to the amboy package's internal registry of job types. This registry is used to support serialization and de-serialization of between persistence layers.

func GetCheckFactory Uses

func GetCheckFactory(name string) (dependency.CheckFactory, error)

GetCheckFactory returns a callback function factory for use in dependencies

func GetDependencyFactory Uses

func GetDependencyFactory(name string) (dependency.ManagerFactory, error)

GetDependencyFactory returns a dependency.Manager factory function from the registry based on the name produced. If the name does not exist, then the error value is non-nil.

func JobTypeNames Uses

func JobTypeNames() <-chan string

JobTypeNames returns an iterator of all registered Job types

type DependencyInterchange Uses

type DependencyInterchange struct {
    Type       string         `json:"type" bson:"type" yaml:"type"`
    Version    int            `json:"version" bson:"version" yaml:"version"`
    Edges      []string       `bson:"edges" json:"edges" yaml:"edges"`
    Dependency *rawDependency `json:"dependency" bson:"dependency" yaml:"dependency"`

DependencyInterchange objects are a standard form for dependency.Manager objects. Amboy (should) only pass DependencyInterchange objects between processes, which have the type information in easy to access and index-able locations.

type JobFactory Uses

type JobFactory func() amboy.Job

JobFactory is an alias for a function that returns a Job interface. All Job implementation should have a factory function with this signature to use with the amboy.RegisterJobType and amboy.JobFactory functions that use an internal registry of jobs to handle correct serialization and de-serialization of job objects.

func GetJobFactory Uses

func GetJobFactory(name string) (JobFactory, error)

GetJobFactory produces Job objects of specific implementations based on the type name, used in RegisterJobType and in the JobType.Name field.

type JobInterchange Uses

type JobInterchange struct {
    Name       string                 `json:"name" bson:"_id" yaml:"name"`
    Type       string                 `json:"type" bson:"type" yaml:"type"`
    Group      string                 `bson:"group,omitempty" json:"group,omitempty" yaml:"group,omitempty"`
    Version    int                    `json:"version" bson:"version" yaml:"version"`
    Priority   int                    `json:"priority" bson:"priority" yaml:"priority"`
    Status     amboy.JobStatusInfo    `bson:"status" json:"status" yaml:"status"`
    TimeInfo   amboy.JobTimeInfo      `bson:"time_info" json:"time_info,omitempty" yaml:"time_info,omitempty"`
    Job        *rawJob                `json:"job,omitempty" bson:"job,omitempty" yaml:"job,omitempty"`
    Dependency *DependencyInterchange `json:"dependency,omitempty" bson:"dependency,omitempty" yaml:"dependency,omitempty"`

JobInterchange provides a consistent way to describe and reliably serialize Job objects between different queue instances. Interchange is also used internally as part of JobGroup Job type.

func MakeJobInterchange Uses

func MakeJobInterchange(j amboy.Job, f amboy.Format) (*JobInterchange, error)

MakeJobInterchange changes a Job interface into a JobInterchange structure, for easier serialization.

func (*JobInterchange) Raw Uses

func (j *JobInterchange) Raw() []byte

Raw returns the serialized version of the job.

func (*JobInterchange) Resolve Uses

func (j *JobInterchange) Resolve(f amboy.Format) (amboy.Job, error)

Resolve reverses the process of ConvertToInterchange and converts the interchange format to a Job object using the types in the registry. Returns an error if the job type of the JobInterchange object isn't registered or the current version of the job produced by the registry is *not* the same as the version of the Job.

Package registry imports 9 packages (graph) and is imported by 26 packages. Updated 2019-05-24. Refresh now. Tools for package owners.