summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2022-04-29 22:25:27 +0200
committerValery Piashchynski <[email protected]>2022-04-29 22:25:27 +0200
commit2c0299332da3b84f1a489180c5e0123575a5088e (patch)
tree87ddf626c16587d1547f6ad56ec185a30728751f
parent3474c11c987cb22dc1a7c4b15c957e127d2571ca (diff)
fix terminal output redirect
Signed-off-by: Valery Piashchynski <[email protected]>
-rw-r--r--go.mod5
-rw-r--r--go.sum8
-rw-r--r--internal/cli/reset/command.go69
-rw-r--r--internal/cli/reset/command_test.go3
-rw-r--r--internal/cli/root.go2
-rwxr-xr-xrr_newbin0 -> 36278272 bytes
6 files changed, 22 insertions, 65 deletions
diff --git a/go.mod b/go.mod
index bc725045..6a2f9123 100644
--- a/go.mod
+++ b/go.mod
@@ -7,7 +7,6 @@ require (
github.com/dustin/go-humanize v1.0.0
github.com/fatih/color v1.13.0
github.com/joho/godotenv v1.4.0
- github.com/mattn/go-runewidth v0.0.13
github.com/olekukonko/tablewriter v0.0.5
github.com/roadrunner-server/amqp/v2 v2.13.0
github.com/roadrunner-server/api/v2 v2.14.0
@@ -52,12 +51,9 @@ require (
github.com/spf13/viper v1.11.0
github.com/stretchr/testify v1.7.1
github.com/temporalio/roadrunner-temporal v1.4.0-rc.1
- github.com/vbauerster/mpb/v5 v5.4.0
)
require (
- github.com/VividCortex/ewma v1.2.0 // indirect
- github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/aws/aws-sdk-go-v2 v1.16.3 // indirect
github.com/aws/aws-sdk-go-v2/config v1.15.4 // indirect
@@ -109,6 +105,7 @@ require (
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
+ github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mholt/acmez v1.0.2 // indirect
github.com/miekg/dns v1.1.48 // indirect
diff --git a/go.sum b/go.sum
index 11cf91ca..6007ce07 100644
--- a/go.sum
+++ b/go.sum
@@ -42,11 +42,6 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/Shopify/sarama v1.30.0/go.mod h1:zujlQQx1kzHsh4jfV1USnptCQrHAEZ2Hk8fTKCulPVs=
github.com/Shopify/toxiproxy/v2 v2.1.6-0.20210914104332-15ea381dcdae/go.mod h1:/cvHQkZ1fst0EmZnA5dFtiQdWCNCFYzb+uE2vqVgvx0=
-github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
-github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
-github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
-github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
-github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
@@ -564,8 +559,6 @@ github.com/valyala/fasthttp v1.36.0 h1:NhqfO/cB7Ajn1czkKnWkMHyPYr5nyND14ZGPk23g0
github.com/valyala/fasthttp v1.36.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
-github.com/vbauerster/mpb/v5 v5.4.0 h1:n8JPunifvQvh6P1D1HAl2Ur9YcmKT1tpoUuiea5mlmg=
-github.com/vbauerster/mpb/v5 v5.4.0/go.mod h1:fi4wVo7BVQ22QcvFObm+VwliQXlV1eBT8JDaKXR4JGI=
github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU=
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
@@ -802,7 +795,6 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201207223542-d4d67f95c62d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20201218084310-7d0127a74742/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
diff --git a/internal/cli/reset/command.go b/internal/cli/reset/command.go
index ce29d248..084cfeff 100644
--- a/internal/cli/reset/command.go
+++ b/internal/cli/reset/command.go
@@ -1,23 +1,17 @@
package reset
import (
- "fmt"
+ "log"
"sync"
internalRpc "github.com/roadrunner-server/roadrunner/v2/internal/rpc"
- "github.com/fatih/color"
- "github.com/mattn/go-runewidth"
"github.com/roadrunner-server/errors"
"github.com/spf13/cobra"
- "github.com/vbauerster/mpb/v5"
- "github.com/vbauerster/mpb/v5/decor"
)
-var spinnerStyle = []string{"∙∙∙", "●∙∙", "∙●∙", "∙∙●", "∙∙∙"} //nolint:gochecknoglobals
-
// NewCommand creates `reset` command.
-func NewCommand(cfgFile *string, override *[]string) *cobra.Command { //nolint:funlen
+func NewCommand(cfgFile *string, override *[]string, silent *bool) *cobra.Command {
return &cobra.Command{
Use: "reset",
Short: "Reset workers of all or specific RoadRunner service",
@@ -39,69 +33,42 @@ func NewCommand(cfgFile *string, override *[]string) *cobra.Command { //nolint:f
defer func() { _ = client.Close() }()
- services := args // by default we expect services list from user
- if len(services) == 0 { // but if nothing was passed - request all services list
- if err = client.Call(resetterList, true, &services); err != nil {
+ plugins := args // by default we expect services list from user
+ if len(plugins) == 0 { // but if nothing was passed - request all services list
+ if err = client.Call(resetterList, true, &plugins); err != nil {
return err
}
}
var wg sync.WaitGroup
- wg.Add(len(services))
-
- pr := mpb.New(mpb.WithWaitGroup(&wg), mpb.WithWidth(6)) //nolint:gomnd
-
- for _, service := range services {
- var (
- bar *mpb.Bar
- name = runewidth.FillRight(fmt.Sprintf("Resetting plugin: [%s]", color.HiYellowString(service)), 27)
- result = make(chan interface{})
- )
-
- bar = pr.AddSpinner(
- 1,
- mpb.SpinnerOnMiddle,
- mpb.SpinnerStyle(spinnerStyle),
- mpb.PrependDecorators(decor.Name(name)),
- mpb.AppendDecorators(onComplete(result)),
- )
+ wg.Add(len(plugins))
+ for _, plugin := range plugins {
// simulating some work
- go func(service string, result chan interface{}) {
+ go func(p string) {
+ if !*silent {
+ log.Printf("resetting plugin: [%s] ", p)
+ }
defer wg.Done()
- defer bar.Increment()
var done bool
- <-client.Go(resetterReset, service, &done, nil).Done
+ <-client.Go(resetterReset, p, &done, nil).Done
if err != nil {
- result <- errors.E(op, err)
+ log.Println(err)
return
}
- result <- nil
- }(service, result)
+ if !*silent {
+ log.Printf("plugin reset: [%s]", p)
+ }
+ }(plugin)
}
- pr.Wait()
+ wg.Wait()
return nil
},
}
}
-
-func onComplete(result chan interface{}) decor.Decorator {
- return decor.Any(func(s decor.Statistics) string {
- select {
- case r := <-result:
- if err, ok := r.(error); ok {
- return color.HiRedString(err.Error())
- }
-
- return color.HiGreenString("done")
- default:
- return ""
- }
- })
-}
diff --git a/internal/cli/reset/command_test.go b/internal/cli/reset/command_test.go
index 57801453..509354e2 100644
--- a/internal/cli/reset/command_test.go
+++ b/internal/cli/reset/command_test.go
@@ -10,7 +10,8 @@ import (
func TestCommandProperties(t *testing.T) {
path := ""
- cmd := reset.NewCommand(&path, nil)
+ f := false
+ cmd := reset.NewCommand(&path, nil, &f)
assert.Equal(t, "reset", cmd.Use)
assert.NotNil(t, cmd.RunE)
diff --git a/internal/cli/root.go b/internal/cli/root.go
index 0df74be0..50f93795 100644
--- a/internal/cli/root.go
+++ b/internal/cli/root.go
@@ -96,7 +96,7 @@ func NewCommand(cmdName string) *cobra.Command { //nolint:funlen
cmd.AddCommand(
workers.NewCommand(cfgFile, override),
- reset.NewCommand(cfgFile, override),
+ reset.NewCommand(cfgFile, override, silent),
serve.NewCommand(override, cfgFile, silent),
)
diff --git a/rr_new b/rr_new
new file mode 100755
index 00000000..686f0b41
--- /dev/null
+++ b/rr_new
Binary files differ