From a52341d0344e2f0cda126d9596fb5e897405785f Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Sun, 10 Jun 2018 18:30:05 +0300 Subject: rr is working now --- cmd/rr/http/reload.go | 57 ---------------------------------------- cmd/rr/http/reset.go | 58 +++++++++++++++++++++++++++++++++++++++++ cmd/rr/http/workers.go | 70 +++++++++++++++++++++++++++++++++----------------- 3 files changed, 104 insertions(+), 81 deletions(-) delete mode 100644 cmd/rr/http/reload.go create mode 100644 cmd/rr/http/reset.go (limited to 'cmd/rr') diff --git a/cmd/rr/http/reload.go b/cmd/rr/http/reload.go deleted file mode 100644 index 06149065..00000000 --- a/cmd/rr/http/reload.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2018 SpiralScout -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -package http - -import ( - "errors" - "github.com/spf13/cobra" - rr "github.com/spiral/roadrunner/cmd/rr/cmd" -) - -func init() { - rr.CLI.AddCommand(&cobra.Command{ - Use: "http:reload", - Short: "Reload RoadRunner worker pools for the HTTP service", - RunE: reloadHandler, - }) -} - -func reloadHandler(cmd *cobra.Command, args []string) error { - if !rr.Container.Has("rpc") { - return errors.New("RPC service is not configured") - } - return nil - - //todo: change - //client, err := rr.Container.Get("rpc").(*rpc.Service).Client() - //if err != nil { - // return err - //} - //defer client.Close() - // - //var r string - //if err := client.Call("http.Reset", true, &r); err != nil { - // return err - //} - // - //rr.Logger.Info("http.service: restarting worker pool") - //return nil -} diff --git a/cmd/rr/http/reset.go b/cmd/rr/http/reset.go new file mode 100644 index 00000000..f5c100cc --- /dev/null +++ b/cmd/rr/http/reset.go @@ -0,0 +1,58 @@ +// Copyright (c) 2018 SpiralScout +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +package http + +import ( + "errors" + "github.com/spf13/cobra" + rr "github.com/spiral/roadrunner/cmd/rr/cmd" + "github.com/spiral/roadrunner/rpc" + "github.com/spiral/roadrunner/service" +) + +func init() { + rr.CLI.AddCommand(&cobra.Command{ + Use: "http:reset", + Short: "Reload RoadRunner worker pools for the HTTP service", + RunE: reloadHandler, + }) +} + +func reloadHandler(cmd *cobra.Command, args []string) error { + svc, st := rr.Container.Get(rpc.Name) + if st < service.StatusConfigured { + return errors.New("RPC service is not configured") + } + + client, err := svc.(*rpc.Service).Client() + if err != nil { + return err + } + defer client.Close() + + var r string + if err := client.Call("http.Reset", true, &r); err != nil { + return err + } + + rr.Logger.Info("http: restarting worker pool") + return nil +} diff --git a/cmd/rr/http/workers.go b/cmd/rr/http/workers.go index c9aa5b04..62730e25 100644 --- a/cmd/rr/http/workers.go +++ b/cmd/rr/http/workers.go @@ -24,6 +24,14 @@ import ( "errors" "github.com/spf13/cobra" rr "github.com/spiral/roadrunner/cmd/rr/cmd" + "github.com/spiral/roadrunner/rpc" + "github.com/spiral/roadrunner/service" + "github.com/spiral/roadrunner/http" + "github.com/olekukonko/tablewriter" + "os" + "strconv" + "time" + "github.com/fatih/color" ) func init() { @@ -35,33 +43,47 @@ func init() { } func workersHandler(cmd *cobra.Command, args []string) error { - if !rr.Container.Has("rpc") { + svc, st := rr.Container.Get(rpc.Name) + if st < service.StatusConfigured { return errors.New("RPC service is not configured") } - //todo: change - //client, err := rr.Container.Get("rpc").(*rpc.Service).Client() - //if err != nil { - // return err - //} - //defer client.Close() + client, err := svc.(*rpc.Service).Client() + if err != nil { + return err + } + defer client.Close() + + var r http.WorkerList + if err := client.Call("http.Workers", true, &r); err != nil { + panic(err) + } + + tw := tablewriter.NewWriter(os.Stdout) + tw.SetHeader([]string{"PID", "Status", "Handled Jobs", "Alive"}) + + for _, w := range r.Workers { + tw.Append([]string{ + color.YellowString(strconv.Itoa(w.Pid)), + renderStatus(w.Status), + renderJobs(w.NumJobs), + renderAlive(time.Unix(0, w.Created)), + }) + } + + tw.Render() - //var r http.WorkerList - //if err := client.Call("http.Workers", true, &r); err != nil { - // panic(err) - //} - // - //tw := tablewriter.NewWriter(os.Stdout) - //tw.SetHeader([]string{"PID", "Status", "Num Execs"}) - // - //for _, w := range r.Workers { - // tw.Append([]string{ - // strconv.Itoa(w.Pid), - // w.Status, - // strconv.Itoa(int(w.NumExecs)), - // }) - //} - // - //tw.Render() return nil } + +func renderStatus(status string) string { + return status +} + +func renderJobs(number uint64) string { + return strconv.Itoa(int(number)) +} + +func renderAlive(t time.Time) string { + return time.Now().Sub(t).String() +} -- cgit v1.2.3