Skip to content

Commit

Permalink
chore: add lsq
Browse files Browse the repository at this point in the history
  • Loading branch information
flowerinthenight committed Jul 20, 2023
1 parent 444ffe3 commit 3d3bed4
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 3 deletions.
78 changes: 78 additions & 0 deletions cmds/runtime/lsq.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package runtime

import (
"context"
"io"

"github.com/alphauslabs/blue-internal-go/tucp/v1"
"github.com/alphauslabs/bluectl/pkg/logger"
"github.com/alphauslabs/tucp/pkg/connection"
"github.com/spf13/cobra"
)

func LsqCmd() *cobra.Command {
var (
purge string
)

cmd := &cobra.Command{
Use: "lsq [next]",
Short: "Inspect current queue count",
Long: `Inspect current queue count. Only available in production.
The optional [next] argument is different than the --next flag: the
--next flag is not supported, while the [next] argument means query
the next environment from prod, which is the correct one.`,
Run: func(cmd *cobra.Command, args []string) {
ctx := context.Background()
con, err := connection.New(ctx)
if err != nil {
logger.Errorf("connection.New failed: %v", err)
return
}

defer con.Close()
client := tucp.NewTuControlPlaneClient(con)
req := tucp.ReadProcessQueuesRequest{}
if len(args) > 0 {
switch {
case args[0] != "next":
logger.Errorf("invalid args: should be 'next'")
return
default:
req.Env = args[0] // next
}
}

req.Purge = purge
stream, err := client.ReadProcessQueues(ctx, &req)
if err != nil {
logger.Errorf("ReadProcessQueues failed: %v", err)
return
}

loop:
for {
v, err := stream.Recv()
switch {
case err == io.EOF:
break loop
case err != nil && err != io.EOF:
logger.Error(err)
break loop
}

switch {
case v.Code != 0:
logger.Errorf("%v", v.Message)
default:
logger.Infof("%v", v.Message)
}
}
},
}

cmd.Flags().SortFlags = false
cmd.Flags().StringVar(&purge, "purge", purge, "comma-separated org list to purge, or 'all'")
return cmd
}
21 changes: 21 additions & 0 deletions cmds/runtime/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package runtime

import (
"github.com/alphauslabs/bluectl/pkg/logger"
"github.com/spf13/cobra"
)

func RuntimeCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "runtime",
Short: "Subcommand for runtime-related operations",
Long: `Subcommand for runtime-related operations.`,
Run: func(cmd *cobra.Command, args []string) {
logger.Info("see -h for more information")
},
}

cmd.Flags().SortFlags = false
cmd.AddCommand(LsqCmd())
return cmd
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/alphauslabs/tucp
go 1.20

require (
github.com/alphauslabs/blue-internal-go v0.3.0
github.com/alphauslabs/blue-internal-go v0.4.3
github.com/alphauslabs/bluectl v0.34.12
github.com/fatih/color v1.15.0
github.com/spf13/cobra v1.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/alphauslabs/blue-internal-go v0.3.0 h1:iGKlYT0jF5smRWTR8Mv0TV3112eQODcwZbnWp2zIL6w=
github.com/alphauslabs/blue-internal-go v0.3.0/go.mod h1:vGxoJsulgwXfaeD8frjDQ8zdkcNle1Nly/kMeb+2g/U=
github.com/alphauslabs/blue-internal-go v0.4.3 h1:fzzHEM/7MV+rucSoIsvjD0Glu4kUKpJyb3q8Dpr9jHM=
github.com/alphauslabs/blue-internal-go v0.4.3/go.mod h1:vGxoJsulgwXfaeD8frjDQ8zdkcNle1Nly/kMeb+2g/U=
github.com/alphauslabs/bluectl v0.34.12 h1:aoWpp/idpdzTWixSbcaEBXDCcykYxLZK1P+e/owTqE8=
github.com/alphauslabs/bluectl v0.34.12/go.mod h1:mV0slUtKni1oP6HeroZcw8Jb5BxeC5Ty4S3Ay6CcC34=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/alphauslabs/bluectl/pkg/logger"
"github.com/alphauslabs/tucp/cmds/invoice"
"github.com/alphauslabs/tucp/cmds/runtime"
"github.com/alphauslabs/tucp/params"
"github.com/fatih/color"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -84,6 +85,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&params.RunEnv, "env", "prod", "dev, next, or prod")
rootCmd.AddCommand(
invoice.InvoiceCmd(),
runtime.RuntimeCmd(),
)
}

Expand Down

0 comments on commit 3d3bed4

Please sign in to comment.