From 9d5fe4f6a98b30fd73be8259f84fa595ac994a71 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Thu, 17 Dec 2020 02:34:44 +0300 Subject: huge refactor --- plugins/http/plugin.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'plugins/http/plugin.go') diff --git a/plugins/http/plugin.go b/plugins/http/plugin.go index 13299da1..9cb01d4b 100644 --- a/plugins/http/plugin.go +++ b/plugins/http/plugin.go @@ -15,10 +15,12 @@ import ( "github.com/hashicorp/go-multierror" "github.com/spiral/endure" "github.com/spiral/errors" - "github.com/spiral/roadrunner/v2" "github.com/spiral/roadrunner/v2/interfaces/log" - factory "github.com/spiral/roadrunner/v2/interfaces/server" + "github.com/spiral/roadrunner/v2/interfaces/pool" + "github.com/spiral/roadrunner/v2/interfaces/server" "github.com/spiral/roadrunner/v2/interfaces/status" + "github.com/spiral/roadrunner/v2/interfaces/worker" + poolImpl "github.com/spiral/roadrunner/v2/pkg/pool" "github.com/spiral/roadrunner/v2/plugins/config" "github.com/spiral/roadrunner/v2/plugins/http/attributes" "github.com/spiral/roadrunner/v2/util" @@ -47,17 +49,17 @@ type Plugin struct { sync.Mutex configurer config.Configurer - server factory.Server + server server.Server log log.Logger cfg *Config // middlewares to chain mdwr middleware // Event listener to stdout - listener util.EventListener + listener worker.EventListener // Pool which attached to all servers - pool roadrunner.Pool + pool pool.Pool // servers RR handler handler Handle @@ -69,7 +71,7 @@ type Plugin struct { } // AddListener attaches server event controller. -func (s *Plugin) AddListener(listener util.EventListener) { +func (s *Plugin) AddListener(listener worker.EventListener) { // save listeners for Reset s.listener = listener s.pool.AddListener(listener) @@ -77,7 +79,7 @@ func (s *Plugin) AddListener(listener util.EventListener) { // Init must return configure svc and return true if svc hasStatus enabled. Must return error in case of // misconfiguration. Services must not be used without proper configuration pushed first. -func (s *Plugin) Init(cfg config.Configurer, log log.Logger, server factory.Server) error { +func (s *Plugin) Init(cfg config.Configurer, log log.Logger, server server.Server) error { const op = errors.Op("http Init") err := cfg.UnmarshalKey(PluginName, &s.cfg) if err != nil { @@ -97,7 +99,7 @@ func (s *Plugin) Init(cfg config.Configurer, log log.Logger, server factory.Serv return errors.E(op, errors.Disabled) } - s.pool, err = server.NewWorkerPool(context.Background(), roadrunner.PoolConfig{ + s.pool, err = server.NewWorkerPool(context.Background(), poolImpl.Config{ Debug: s.cfg.Pool.Debug, NumWorkers: s.cfg.Pool.NumWorkers, MaxJobs: s.cfg.Pool.MaxJobs, @@ -122,7 +124,7 @@ func (s *Plugin) logCallback(event interface{}) { s.log.Debug("http handler response received", "elapsed", ev.Elapsed().String(), "remote address", ev.Request.RemoteAddr) case ErrorEvent: s.log.Error("error event received", "elapsed", ev.Elapsed().String(), "error", ev.Error) - case roadrunner.WorkerEvent: + case worker.Event: s.log.Debug("worker event received", "event", ev.Event, "worker state", ev.Worker.State()) default: fmt.Println(event) @@ -284,7 +286,7 @@ func (s *Plugin) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // Server returns associated pool workers -func (s *Plugin) Workers() []roadrunner.WorkerBase { +func (s *Plugin) Workers() []worker.BaseProcess { return s.pool.Workers() } @@ -305,7 +307,7 @@ func (s *Plugin) Reset() error { return errors.E(op, err) } - s.pool, err = s.server.NewWorkerPool(context.Background(), roadrunner.PoolConfig{ + s.pool, err = s.server.NewWorkerPool(context.Background(), poolImpl.Config{ Debug: s.cfg.Pool.Debug, NumWorkers: s.cfg.Pool.NumWorkers, MaxJobs: s.cfg.Pool.MaxJobs, -- cgit v1.2.3 From 40cfd9f6b44dfe987bfbf010bf67b32abdc64208 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Thu, 17 Dec 2020 03:16:55 +0300 Subject: Now better --- plugins/http/plugin.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'plugins/http/plugin.go') diff --git a/plugins/http/plugin.go b/plugins/http/plugin.go index 9cb01d4b..460263f6 100644 --- a/plugins/http/plugin.go +++ b/plugins/http/plugin.go @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/go-multierror" "github.com/spiral/endure" "github.com/spiral/errors" + "github.com/spiral/roadrunner/v2/interfaces/events" "github.com/spiral/roadrunner/v2/interfaces/log" "github.com/spiral/roadrunner/v2/interfaces/pool" "github.com/spiral/roadrunner/v2/interfaces/server" @@ -55,8 +56,8 @@ type Plugin struct { cfg *Config // middlewares to chain mdwr middleware - // Event listener to stdout - listener worker.EventListener + // WorkerEvent listener to stdout + listener events.EventListener // Pool which attached to all servers pool pool.Pool @@ -71,7 +72,7 @@ type Plugin struct { } // AddListener attaches server event controller. -func (s *Plugin) AddListener(listener worker.EventListener) { +func (s *Plugin) AddListener(listener events.EventListener) { // save listeners for Reset s.listener = listener s.pool.AddListener(listener) @@ -124,8 +125,8 @@ func (s *Plugin) logCallback(event interface{}) { s.log.Debug("http handler response received", "elapsed", ev.Elapsed().String(), "remote address", ev.Request.RemoteAddr) case ErrorEvent: s.log.Error("error event received", "elapsed", ev.Elapsed().String(), "error", ev.Error) - case worker.Event: - s.log.Debug("worker event received", "event", ev.Event, "worker state", ev.Worker.State()) + case events.WorkerEvent: + s.log.Debug("worker event received", "event", ev.Event, "worker state", ev.Worker.(worker.BaseProcess).State()) default: fmt.Println(event) } -- cgit v1.2.3