Documentation
¶
Index ¶
- Constants
- type Broker
- type Config
- type Dispatcher
- type ErrorHandler
- type EventProvider
- type Handler
- type Job
- type JobError
- type JobEvent
- type Options
- type Pipeline
- func (p Pipeline) Bool(name string, d bool) bool
- func (p Pipeline) Broker() string
- func (p Pipeline) Duration(name string, d time.Duration) time.Duration
- func (p Pipeline) Has(name string) bool
- func (p Pipeline) Integer(name string, d int) int
- func (p Pipeline) Map(name string) Pipeline
- func (p Pipeline) Name() string
- func (p Pipeline) String(name string, d string) string
- func (p Pipeline) With(name string, value interface{}) Pipeline
- type PipelineError
- type PipelineList
- type Pipelines
- type Service
- func (svc *Service) AddListener(l func(event int, ctx interface{}))
- func (svc *Service) Attach(ctr roadrunner.Controller)
- func (svc *Service) Consume(pipe *Pipeline, execPool chan Handler, errHandler ErrorHandler) error
- func (svc *Service) Init(cfg service.Config, log *logrus.Logger, env env.Environment, rpc *rpc.Service) (ok bool, err error)
- func (svc *Service) Push(job *Job) (string, error)
- func (svc *Service) Serve() error
- func (svc *Service) Server() *roadrunner.Server
- func (svc *Service) Stat(pipe *Pipeline) (stat *Stat, err error)
- func (svc *Service) Stop()
- type Stat
- type WorkerList
Constants ¶
const ( // EventPushOK thrown when new job has been added. JobEvent is passed as context. EventPushOK = iota + 1500 // EventPushError caused when job can not be registered. EventPushError // EventJobStart thrown when new job received. EventJobStart // EventJobOK thrown when job execution is successfully completed. JobEvent is passed as context. EventJobOK // EventJobError thrown on all job related errors. See JobError as context. EventJobError // EventPipeConsume when pipeline pipelines has been requested. EventPipeConsume // EventPipeActive when pipeline has started. EventPipeActive // EventPipeStop when pipeline has begun stopping. EventPipeStop // EventPipeStopped when pipeline has been stopped. EventPipeStopped // EventPipeError when pipeline specific error happen. EventPipeError // EventBrokerReady thrown when broken is ready to accept/serve tasks. EventBrokerReady )
const ID = "jobs"
ID defines public service name.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Broker ¶ added in v0.2.0
type Broker interface { // Register broker pipeline. Register(pipe *Pipeline) error // Consume configures pipeline to be consumed. With execPool to nil to disable pipelines. Method can be called before // the service is started! Consume(pipe *Pipeline, execPool chan Handler, errHandler ErrorHandler) error // Push job into the worker. Push(pipe *Pipeline, j *Job) (string, error) // Stat must fetch statistics about given pipeline or return error. Stat(pipe *Pipeline) (stat *Stat, err error) }
Broker manages set of pipelines and provides ability to push jobs into them.
type Config ¶
type Config struct { // Workers configures roadrunner server and worker busy. Workers *roadrunner.ServerConfig // Dispatch defines where and how to match jobs. Dispatch map[string]*Options // Pipelines defines mapping between PHP job pipeline and associated job broker. Pipelines map[string]*Pipeline // Consuming specifies names of pipelines to be consumed on service start. Consume []string // contains filtered or unexported fields }
Config defines settings for job broker, workers and job-pipeline mapping.
func (*Config) MatchPipeline ¶ added in v1.0.0
MatchPipeline locates the pipeline associated with the job.
type Dispatcher ¶ added in v1.0.0
Dispatcher provides ability to automatically locate the pipeline for the specific job and update job options (if none set).
type ErrorHandler ¶ added in v0.2.0
ErrorHandler handles job execution errors.
type EventProvider ¶ added in v1.0.0
type EventProvider interface { // Listen attaches the even listener. Listen(lsn func(event int, ctx interface{})) }
EventProvider defines the ability to throw events for the broker.
type Job ¶ added in v0.2.0
type Job struct { // Job contains name of job broker (usually PHP class). Job string `json:"job"` // 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.
type JobError ¶ added in v1.0.0
type JobError struct { // String is job id. ID string // Job is failed job. Job *Job // Caused contains job specific error. Caused error // contains filtered or unexported fields }
JobError represents singular Job error event.
type JobEvent ¶ added in v1.0.0
type JobEvent struct { // String is job id. ID string // Job is failed job. Job *Job // contains filtered or unexported fields }
JobEvent represent job event.
type Options ¶ added in v0.2.0
type Options struct { // Pipeline manually specified pipeline. Pipeline string `json:"pipeline,omitempty"` // Delay defines time duration to delay execution for. Defaults to none. Delay int `json:"delay,omitempty"` // Attempts define maximum job retries. Attention, value 1 will only allow job to execute once (without retry). // Minimum valuable value is 2. Attempts int `json:"maxAttempts,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"` }
Options carry information about how to handle given job.
func (*Options) CanRetry ¶ added in v1.0.0
CanRetry must return true if broker is allowed to re-run the job.
func (*Options) DelayDuration ¶ added in v0.2.0
DelayDuration returns delay duration in a form of time.Duration.
func (*Options) RetryDuration ¶ added in v0.2.0
RetryDuration returns retry delay duration in a form of time.Duration.
func (*Options) TimeoutDuration ¶ added in v0.2.0
TimeoutDuration returns timeout duration in a form of time.Duration.
type Pipeline ¶ added in v0.2.0
type Pipeline map[string]interface{}
Pipeline defines pipeline options.
func (Pipeline) Bool ¶ added in v1.0.0
Bool must return option value as string or return default value.
func (Pipeline) Duration ¶ added in v1.0.0
Duration must return option value as time.Duration (seconds) or return default value.
func (Pipeline) Integer ¶ added in v1.0.0
Integer must return option value as string or return default value.
type PipelineError ¶ added in v1.0.0
type PipelineError struct { // Pipeline is associated pipeline. Pipeline *Pipeline // Caused send by broker. Caused error }
PipelineError defines pipeline specific errors.
func (*PipelineError) Error ¶ added in v1.0.0
func (e *PipelineError) Error() string
Error returns error message.
type PipelineList ¶ added in v1.0.0
type PipelineList struct { // Pipelines is list of pipeline stats. Pipelines []*Stat `json:"pipelines"` }
PipelineList contains list of pipeline stats.
type Pipelines ¶ added in v1.0.0
type Pipelines []*Pipeline
Pipelines is list of Pipeline.
type Service ¶
type Service struct { // Associated parent Brokers map[string]Broker // contains filtered or unexported fields }
Service wraps roadrunner container and manage set of parent within it.
func (*Service) AddListener ¶ added in v1.0.0
AddListener attaches event listeners to the service and all underlying brokers.
func (*Service) Attach ¶ added in v1.1.0
func (svc *Service) Attach(ctr roadrunner.Controller)
Attach attaches cr. Currently only one cr is supported.
func (*Service) Consume ¶ added in v1.0.0
func (svc *Service) Consume(pipe *Pipeline, execPool chan Handler, errHandler ErrorHandler) error
Consume enables or disables pipeline pipelines using given handlers.
func (*Service) Init ¶
func (svc *Service) Init( cfg service.Config, log *logrus.Logger, env env.Environment, rpc *rpc.Service, ) (ok bool, err error)
Init configures job service.
func (*Service) Server ¶ added in v1.1.4
func (svc *Service) Server() *roadrunner.Server
Server returns associated rr server (if any).
type Stat ¶ added in v1.0.0
type Stat struct { // Pipeline name. Pipeline string // Broken is name of associated broker. Broker string // InternalName defines internal broker specific pipeline name. InternalName string // Consuming indicates that pipeline is pipelines jobs. Consuming bool // testQueue defines number of pending jobs. Queue int64 // Active defines number of jobs which are currently being processed. Active int64 // Delayed defines number of jobs which are being processed. Delayed int64 }
Stat contains information about pipeline.
type WorkerList ¶ added in v1.0.0
WorkerList contains list of workers.