registry

package
v0.0.0-...-2a91a1d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCheckType

func AddCheckType(name string, f dependency.CheckFactory)

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

func AddDependencyType

func AddDependencyType(name string, f dependency.ManagerFactory)

AddDependencyType registers a new dependency.Manager factories.

func AddJobType

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

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

GetCheckFactory returns a callback function factory for use in dependencies

func GetDependencyFactory

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

func JobTypeNames() <-chan string

JobTypeNames returns an iterator of all registered Job types

Types

type DependencyInterchange

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

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

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

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

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

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

Raw returns the serialized version of the job.

func (*JobInterchange) Resolve

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL