From 31e4bb7b236fe0ae59fd42d66af0d718b67a2a4b Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Thu, 3 Dec 2020 13:08:38 +0300 Subject: Initial commit of checker plugin --- plugins/http/plugin.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'plugins/http') diff --git a/plugins/http/plugin.go b/plugins/http/plugin.go index 79e8aa94..371cdb91 100644 --- a/plugins/http/plugin.go +++ b/plugins/http/plugin.go @@ -18,6 +18,7 @@ import ( "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/status" "github.com/spiral/roadrunner/v2/plugins/config" "github.com/spiral/roadrunner/v2/plugins/http/attributes" "github.com/spiral/roadrunner/v2/util" @@ -341,6 +342,22 @@ func (s *Plugin) AddMiddleware(name endure.Named, m Middleware) { s.mdwr[name.Name()] = m } +// Status return status of the particular plugin +func (s *Plugin) Status() status.Status { + workers := s.Workers() + for i := 0; i < len(workers); i++ { + if workers[i].State().IsActive() { + return status.Status{ + Code: http.StatusOK, + } + } + } + // if there are no workers, threat this as error + return status.Status{ + Code: http.StatusInternalServerError, + } +} + func (s *Plugin) redirect(w http.ResponseWriter, r *http.Request) bool { if s.https != nil && r.TLS == nil && s.cfg.SSL.Redirect { target := &url.URL{ -- cgit v1.2.3