jobs

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2018 License: MIT Imports: 10 Imported by: 0

README

Async Jobs: Local Queue, Beanstalk, Amazon SQS

Latest Stable Version Build Status Codecov

Documentation

Index

Constants

View Source
const BrokersConfig = "Brokers"

BrokersConfig defines config section related to Brokers configuration.

View Source
const (
	// ID defines Listen service public alias.
	ID = "jobs"
)

Variables

This section is empty.

Functions

func Listener added in v0.2.1

func Listener(logger *logrus.Logger) func(event int, ctx interface{})

Listener creates new debug listener.

Types

type Broker added in v0.2.0

type Broker interface {
	// Listen configures broker with list of pipelines to listen and handler function.
	Listen(pipelines []*Pipeline, pool chan Handler, err ErrorHandler) error

	// Serve broker must listen for all associated pipelines and consume given jobs.
	Serve() error

	// Stop must stop broker.
	Stop()

	// Push new job to the broker. Must return job id or error.
	Push(p *Pipeline, j *Job) (id string, err error)
}

Broker represents single broker abstraction.

type Config

type Config struct {
	// Workers configures roadrunner server and worker busy.
	Workers *roadrunner.ServerConfig

	// Pipelines defines mapping between PHP job pipeline and associated job broker.
	Pipelines []*Pipeline
}

Config defines settings for job broker, workers and routing PipelineOptions.

func (*Config) Hydrate

func (c *Config) Hydrate(cfg service.Config) error

Hydrate populates config values.

type ErrorHandler added in v0.2.0

type ErrorHandler func(id string, j *Job, err error) error

Listen handles job execution.

type Handler added in v0.2.0

type Handler func(id string, j *Job) error

Listen handles job execution.

type Job added in v0.2.0

type Job struct {
	// Job contains name of job broker (usually PHP class).
	Job string `json:"job"`

	// Attempt is number of job attempt if case of error.
	Attempt int `json:"attempt"`

	// Payload is string data (usually JSON) passed to Job broker.
	Payload string `json:"payload"`

	// Options contains set of PipelineOptions specific to job execution. Can be empty.
	Options Options `json:"options,omitempty"`
}

Job carries information about single job.

func (*Job) Body added in v0.2.0

func (j *Job) Body() []byte

Body packs job payload into binary payload.

func (*Job) CanRetry added in v0.2.0

func (j *Job) CanRetry() bool

CanRetry must return true if broker is allowed to re-run the job.

func (*Job) Context added in v0.2.0

func (j *Job) Context(id string) ([]byte, error)

Context pack job context (job, id) into binary payload.

type Options added in v0.2.0

type Options struct {
	// Delay defines time duration to delay execution for. Defaults to none.
	Delay int `json:"delay,omitempty"`

	// RetryDelay defines for how long job should be waiting until next retry. Defaults to none.
	RetryDelay int `json:"retryDelay,omitempty"`

	// Reserve defines for how broker should wait until treating job are failed. Defaults to 30 min.
	Timeout int `json:"timeout,omitempty"`

	// Maximum job retries. Defaults to none.
	MaxAttempts int `json:"maxAttempts,omitempty"`
}

Options carry information about how to handle given job.

func (*Options) DelayDuration added in v0.2.0

func (o *Options) DelayDuration() time.Duration

DelayDuration returns delay duration in a form of time.Duration.

func (*Options) RetryDuration added in v0.2.0

func (o *Options) RetryDuration() time.Duration

RetryDuration returns retry delay duration in a form of time.Duration.

func (*Options) TimeoutDuration added in v0.2.0

func (o *Options) TimeoutDuration() time.Duration

DelayDuration returns timeout duration in a form of time.Duration.

type Pipeline added in v0.2.0

type Pipeline struct {
	// Broker defines name of associated broker.
	Broker string

	// Listen define job matching pattern (i.e. - "app.jobs.email")
	Handle []string

	// Retry defined number of job retries in case of error. Default none.
	Retry int

	// RetryDelay defines for how long wait till job retry.
	RetryDelay int

	// Listen tells the service that this pipeline must be consumed by the service.
	Listen bool

	// Options are broker specific PipelineOptions.
	Options PipelineOptions
}

Pipeline describes broker specific pipeline.

func (*Pipeline) Has added in v0.2.0

func (p *Pipeline) Has(job string) bool

Listen must return true if pipeline expect to handle given job.

type PipelineOptions added in v0.2.0

type PipelineOptions map[string]interface{}

func (PipelineOptions) Bool added in v0.2.0

func (o PipelineOptions) Bool(name string, d bool) bool

Bool must return option value as string or return default value.

func (PipelineOptions) Duration added in v0.2.0

func (o PipelineOptions) Duration(name string, d time.Duration) time.Duration

Duration must return option value as time.Duration (seconds) or return default value.

func (PipelineOptions) Integer added in v0.2.0

func (o PipelineOptions) Integer(name string, d int) int

Int must return option value as string or return default value.

func (PipelineOptions) String added in v0.2.0

func (o PipelineOptions) String(name string, d string) string

String must return option value as string or return default value.

type Service

type Service struct {
	// Brokers define list of available brokers.
	Brokers map[string]Broker
	// contains filtered or unexported fields
}

Service manages job execution and connection to multiple job pipelines.

func (*Service) Init

func (s *Service) Init(c service.Config, l *logrus.Logger, r *rpc.Service, e env.Environment) (ok bool, err error)

Init configures job service.

func (*Service) Push added in v0.2.0

func (s *Service) Push(j *Job) (string, error)

Push job to associated broker and return job id.

func (*Service) Serve

func (s *Service) Serve() error

Serve serves local rr server and creates broker association.

func (*Service) Stop

func (s *Service) Stop()

Stop all pipelines and rr server.

Directories

Path Synopsis
broker
sqs

Jump to

Keyboard shortcuts

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