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

package registry

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

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.

Index

Package Files

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

func AddDependencyType Uses

func AddDependencyType(name string, f DependencyFactory)

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

func ConvertToJob(j *JobInterchange) (amboy.Job, error)

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

func JobTypeNames Uses

func JobTypeNames() <-chan string

JobTypeNames returns an iterator of all registered Job types

type DependencyFactory Uses

type DependencyFactory func() dependency.Manager

DependencyFactory 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 GetDependencyFactory Uses

func GetDependencyFactory(name string) (DependencyFactory, 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.

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 []byte   `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"`
    Version    int                    `json:"version" bson:"version" yaml:"version"`
    Priority   int                    `bson:"priority" json:"priority" yaml:"priority"`
    Job        []byte                 `json:"job,omitempty" bson:"job,omitempty" yaml:"job,omitempty"`
    Dependency *DependencyInterchange `json:"dependency,omitempty" bson:"dependency,omitempty" yaml:"dependency,omitempty"`
    Status     amboy.JobStatusInfo    `bson:"status" json:"status" yaml:"status"`
}

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) (*JobInterchange, error)

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

Package registry imports 6 packages (graph) and is imported by 15 packages. Updated 2017-12-11. Refresh now. Tools for package owners.