Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add watch interval to queue list #707

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ require (
// Remove 'in body' from errors, fix for Go 1.16 (https://github.com/go-openapi/validate/pull/138).
replace github.com/go-openapi/validate => github.com/flant/go-openapi-validate v0.19.12-flant.0

require github.com/gojuno/minimock/v3 v3.4.3
require (
github.com/buger/goterm v1.0.4
github.com/gojuno/minimock/v3 v3.4.3
)

require (
github.com/DataDog/gostackparse v0.7.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535/go.mod h1:o
github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/buger/goterm v1.0.4 h1:Z9YvGmOih81P0FbVtEYTFF6YsSgxSUKEhf/f9bTMXbY=
github.com/buger/goterm v1.0.4/go.mod h1:HiFWV3xnkolgrBV3mY8m0X0Pumt4zg4QhbdOzQtB8tE=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down Expand Up @@ -343,6 +345,7 @@ golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210331175145-43e1dd70ce54/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
Expand Down
42 changes: 36 additions & 6 deletions pkg/debug/debug-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
"fmt"
"time"

"github.com/buger/goterm"
"gopkg.in/alecthomas/kingpin.v2"

"github.com/flant/shell-operator/pkg/app"
)

var (
outputFormat = "text"
showEmpty = false
outputFormat = "text"
showEmpty = false
watch = false
watchInterval = "1s"
)

func DefineDebugCommands(kpApp *kingpin.Application) {
Expand All @@ -20,16 +23,43 @@

queueListCmd := queueCmd.Command("list", "Dump tasks in all queues.").
Action(func(_ *kingpin.ParseContext) error {
out, err := Queue(DefaultClient()).List(outputFormat, showEmpty)
if err != nil {
return err
var refreshInterval time.Duration
if watch {
goterm.Clear()
goterm.MoveCursor(1, 1)
var err error
refreshInterval, err = time.ParseDuration(watchInterval)
if err != nil {
goterm.Println(fmt.Sprintf("couldn't parse watch refresh interval: %s, default 1s applied\n", err))
refreshInterval = time.Duration(1 * time.Second)

Check failure on line 34 in pkg/debug/debug-cmd.go

View workflow job for this annotation

GitHub Actions / Run linter

unnecessary conversion (unconvert)
}
}
for {
out, err := Queue(DefaultClient()).List(outputFormat, showEmpty)
if err != nil {
return err
}
goterm.Println(string(out))
goterm.Flush()

if !watch {
break
}
time.Sleep(refreshInterval)
goterm.MoveCursor(1, 1)
goterm.Clear()
}
fmt.Println(string(out))
return nil
})
queueListCmd.Flag("show-empty", "Show empty queues.").Short('e').
Default("false").
BoolVar(&showEmpty)
queueListCmd.Flag("watch", "Keep watching.").Short('w').
Default("false").
BoolVar(&watch)
queueListCmd.Flag("watchInterval", "Watch refresh interval.").Short('t').
Default(watchInterval).
StringVar(&watchInterval)
AddOutputJsonYamlTextFlag(queueListCmd)
app.DefineDebugUnixSocketFlag(queueListCmd)

Expand Down
Loading