diff options
Diffstat (limited to 'cmd/rr/http/workers.go')
-rw-r--r-- | cmd/rr/http/workers.go | 59 |
1 files changed, 34 insertions, 25 deletions
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 } |