-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
flowerinthenight
committed
Jul 20, 2023
1 parent
444ffe3
commit 3d3bed4
Showing
5 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters