diff options
author | Wolfy-J <[email protected]> | 2018-06-05 16:23:14 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-05 16:23:14 +0300 |
commit | 76ff8d1c95e087749d559ee5a4f8f0348feafffa (patch) | |
tree | 112630d2d2cfe41d809065034c13b1066b8e05c2 /cmd/rr/http | |
parent | 3c86132f90ef6473b4073a8b1500d01b6114fc30 (diff) |
Cs and refactoring
Diffstat (limited to 'cmd/rr/http')
-rw-r--r-- | cmd/rr/http/register.go | 23 | ||||
-rw-r--r-- | cmd/rr/http/reload.go | 28 | ||||
-rw-r--r-- | cmd/rr/http/workers.go | 59 |
3 files changed, 54 insertions, 56 deletions
diff --git a/cmd/rr/http/register.go b/cmd/rr/http/register.go deleted file mode 100644 index fb828578..00000000 --- a/cmd/rr/http/register.go +++ /dev/null @@ -1,23 +0,0 @@ -package http - -import ( - "github.com/spf13/cobra" - rr "github.com/spiral/roadrunner/cmd/rr/cmd" - "github.com/spiral/roadrunner/http" -) - -func init() { - rr.Services.Register(&http.Service{}) - - rr.CLI.AddCommand(&cobra.Command{ - Use: "http:reload", - Short: "Reload RoadRunner worker pools for the HTTP service", - Run: reloadHandler, - }) - - rr.CLI.AddCommand(&cobra.Command{ - Use: "http:workers", - Short: "List workers associated with RoadRunner HTTP service", - Run: workersHandler, - }) -} diff --git a/cmd/rr/http/reload.go b/cmd/rr/http/reload.go index 6cdba576..0fd3d7e9 100644 --- a/cmd/rr/http/reload.go +++ b/cmd/rr/http/reload.go @@ -23,22 +23,34 @@ package http import ( "github.com/spf13/cobra" rr "github.com/spiral/roadrunner/cmd/rr/cmd" - "github.com/sirupsen/logrus" + "github.com/go-errors/errors" + "github.com/spiral/roadrunner/rpc" ) -func reloadHandler(cmd *cobra.Command, args []string) { - client, err := rr.Services.RCPClient() +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.Services.Has("rpc") { + return errors.New("RPC service is not configured") + } + + client, err := rr.Services.Get("rpc").(*rpc.Service).Client() if err != nil { - logrus.Error(err) - return + return err } defer client.Close() var r string if err := client.Call("http.Reset", true, &r); err != nil { - logrus.Error(err) - return + return err } - logrus.Info("restarting http worker pool") + rr.Logger.Info("http.service: restarting worker pool") + return nil } diff --git a/cmd/rr/http/workers.go b/cmd/rr/http/workers.go index 13e8d21c..63ef0cce 100644 --- a/cmd/rr/http/workers.go +++ b/cmd/rr/http/workers.go @@ -21,38 +21,47 @@ package http import ( - "github.com/olekukonko/tablewriter" "github.com/spf13/cobra" rr "github.com/spiral/roadrunner/cmd/rr/cmd" - "github.com/spiral/roadrunner/http" - "os" - "strconv" - "github.com/sirupsen/logrus" + "errors" + "github.com/spiral/roadrunner/rpc" ) -func workersHandler(cmd *cobra.Command, args []string) { - client, err := rr.Services.RCPClient() - if err != nil { - logrus.Error(err) - return - } - defer client.Close() +func init() { + rr.CLI.AddCommand(&cobra.Command{ + Use: "http:workers", + Short: "List workers associated with RoadRunner HTTP service", + RunE: workersHandler, + }) +} - var r http.WorkerList - if err := client.Call("http.Workers", true, &r); err != nil { - panic(err) +func workersHandler(cmd *cobra.Command, args []string) error { + if !rr.Services.Has("rpc") { + return errors.New("RPC service is not configured") } - 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)), - }) + client, err := rr.Services.Get("rpc").(*rpc.Service).Client() + if err != nil { + return err } + defer client.Close() - 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 } |