diff options
author | Valery Piashchynski <[email protected]> | 2021-06-21 17:01:39 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-06-21 17:01:39 +0300 |
commit | 41bb9fa5938125217a075c60f1e39dc3a9a27537 (patch) | |
tree | ce2997caa62f90279d85f6aa2397996f80791893 /plugins/jobs/config.go | |
parent | bdcfdd28d705e401973da2beb8a11543e362bda4 (diff) |
- Rework dispatcher, pipeline, job (not completely)
Create a config sample with RR2 support. Progress on root JOBS plugin.
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/jobs/config.go')
-rw-r--r-- | plugins/jobs/config.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/plugins/jobs/config.go b/plugins/jobs/config.go new file mode 100644 index 00000000..5c5ad400 --- /dev/null +++ b/plugins/jobs/config.go @@ -0,0 +1,51 @@ +package jobs + +import ( + "github.com/spiral/errors" + poolImpl "github.com/spiral/roadrunner/v2/pkg/pool" +) + +// Config defines settings for job broker, workers and job-pipeline mapping. +type Config struct { + // Workers configures roadrunner server and worker busy. + //Workers *roadrunner.ServerConfig + pool poolImpl.Config + + // 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 + + // parent config for broken options. + pipelines Pipelines + route Dispatcher +} + +// MatchPipeline locates the pipeline associated with the job. +func (c *Config) MatchPipeline(job *Job) (*Pipeline, *Options, error) { + const op = errors.Op("config_match_pipeline") + opt := c.route.match(job) + + pipe := "" + if job.Options != nil { + pipe = job.Options.Pipeline + } + + if pipe == "" && opt != nil { + pipe = opt.Pipeline + } + + if pipe == "" { + return nil, nil, errors.E(op, errors.Errorf("unable to locate pipeline for `%s`", job.Job)) + } + + if p := c.pipelines.Get(pipe); p != nil { + return p, opt, nil + } + + return nil, nil, errors.E(op, errors.Errorf("undefined pipeline `%s`", pipe)) +} |