diff options
Diffstat (limited to 'service/http')
-rw-r--r-- | service/http/attributes/attributes.go | 8 | ||||
-rw-r--r-- | service/http/service.go | 27 |
2 files changed, 21 insertions, 14 deletions
diff --git a/service/http/attributes/attributes.go b/service/http/attributes/attributes.go index 94d0e9c1..77d6ea69 100644 --- a/service/http/attributes/attributes.go +++ b/service/http/attributes/attributes.go @@ -6,7 +6,9 @@ import ( "net/http" ) -const contextKey = "psr:attributes" +type attrKey int + +const contextKey attrKey = iota type attrs map[string]interface{} @@ -41,7 +43,7 @@ func All(r *http.Request) map[string]interface{} { return v.(attrs) } -// get gets the value from request context. It replaces any existing +// Get gets the value from request context. It replaces any existing // values. func Get(r *http.Request, key string) interface{} { v := r.Context().Value(contextKey) @@ -52,7 +54,7 @@ func Get(r *http.Request, key string) interface{} { return v.(attrs).get(key) } -// set sets the key to value. It replaces any existing +// Set sets the key to value. It replaces any existing // values. Context specific. func Set(r *http.Request, key string, value interface{}) error { v := r.Context().Value(contextKey) diff --git a/service/http/service.go b/service/http/service.go index f7fdf2ab..a8f99669 100644 --- a/service/http/service.go +++ b/service/http/service.go @@ -3,6 +3,7 @@ package http import ( "context" "github.com/spiral/roadrunner" + "github.com/spiral/roadrunner/service/env" "github.com/spiral/roadrunner/service/http/attributes" "github.com/spiral/roadrunner/service/rpc" "net/http" @@ -18,10 +19,10 @@ type middleware func(f http.HandlerFunc) http.HandlerFunc // Service manages rr, http servers. type Service struct { - cfg *Config - lsns []func(event int, ctx interface{}) - mdws []middleware - + cfg *Config + env env.Provider + lsns []func(event int, ctx interface{}) + mdws []middleware mu sync.Mutex rr *roadrunner.Server stopping int32 @@ -41,12 +42,13 @@ func (s *Service) AddListener(l func(event int, ctx interface{})) { // 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 *Service) Init(cfg *Config, r *rpc.Service) (bool, error) { +func (s *Service) Init(cfg *Config, r *rpc.Service, e env.Provider) (bool, error) { if !cfg.Enable { return false, nil } s.cfg = cfg + s.env = e if r != nil { r.Register(ID, &rpcServer{s}) } @@ -57,6 +59,13 @@ func (s *Service) Init(cfg *Config, r *rpc.Service) (bool, error) { // Serve serves the svc. func (s *Service) Serve() error { s.mu.Lock() + + if s.env != nil { + for k, v := range s.env.GetEnv() { + s.cfg.Workers.SetEnv(k, v) + } + } + rr := roadrunner.NewServer(s.cfg.Workers) s.rr = rr @@ -116,11 +125,7 @@ func (s *Service) listener(event int, ctx interface{}) { } if event == roadrunner.EventServerFailure { - if atomic.LoadInt32(&s.stopping) != 0 { - // attempting rr server restart - if err := s.rr.Start(); err != nil { - s.Stop() - } - } + // underlying rr server is dead + s.Stop() } } |