File tree Expand file tree Collapse file tree 4 files changed +43
-6
lines changed Expand file tree Collapse file tree 4 files changed +43
-6
lines changed Original file line number Diff line number Diff line change @@ -173,8 +173,9 @@ func newAdminShardManagementCommands() []cli.Command {
173173 {
174174 Name : "list_tasks" ,
175175 Usage : "List tasks for given shard Id and task type" ,
176- Flags : append (
176+ Flags : append (append (
177177 getDBFlags (),
178+ getFlagsForList ()... ),
178179 cli.StringFlag {
179180 Name : FlagTargetCluster ,
180181 Value : "active" ,
Original file line number Diff line number Diff line change @@ -433,11 +433,21 @@ func AdminListTasks(c *cli.Context) {
433433 maxVis := time .Unix (0 , maxVisFlag )
434434
435435 req := & persistence.GetTimerIndexTasksRequest {MinTimestamp : minVis , MaxTimestamp : maxVis }
436- tasks , err := executionManager .GetTimerIndexTasks (req )
437- if err != nil {
438- ErrorAndExit ("Failed to get Timer Tasks" , err )
436+ paginationFunc := func (paginationToken []byte ) ([]interface {}, []byte , error ) {
437+ req .NextPageToken = paginationToken
438+ response , err := executionManager .GetTimerIndexTasks (req )
439+ if err != nil {
440+ return nil , nil , err
441+ }
442+ token := response .NextPageToken
443+
444+ var items []interface {}
445+ for _ , task := range response .Timers {
446+ items = append (items , task )
447+ }
448+ return items , token , nil
439449 }
440- prettyPrintJSONObject ( tasks )
450+ paginate ( c , paginationFunc )
441451 } else if category == commongenpb .TASK_CATEGORY_REPLICATION {
442452 req := & persistence.GetReplicationTasksRequest {}
443453 task , err := executionManager .GetReplicationTasks (req )
Original file line number Diff line number Diff line change @@ -40,7 +40,6 @@ import (
4040// CreatePersistenceFactory returns an initialized persistence managers factory.
4141// The factory allows to easily initialize concrete persistence managers to execute commands against persistence layer
4242func CreatePersistenceFactory (c * cli.Context ) persistenceClient.Factory {
43-
4443 defaultStore , err := CreateDefaultDBConfig (c )
4544 if err != nil {
4645 ErrorAndExit ("CreatePersistenceFactory err" , err )
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ import (
5252 sdkclient "go.temporal.io/temporal/client"
5353
5454 "github.com/temporalio/temporal/common/codec"
55+ "github.com/temporalio/temporal/common/collection"
5556 "github.com/temporalio/temporal/common/payload"
5657 "github.com/temporalio/temporal/common/payloads"
5758 "github.com/temporalio/temporal/common/rpc"
@@ -901,6 +902,32 @@ func showNextPage() bool {
901902 return strings .Trim (input , " " ) == ""
902903}
903904
905+ // paginate creates an interactive CLI mode to control the printing of items
906+ func paginate (c * cli.Context , paginationFn collection.PaginationFn ) error {
907+ more := c .Bool (FlagMore )
908+ pageSize := c .Int (FlagPageSize )
909+ if pageSize == 0 {
910+ pageSize = defaultPageSize
911+ }
912+ iter := collection .NewPagingIterator (paginationFn )
913+
914+ pageItemsCount := 0
915+ for iter .HasNext () {
916+ batch , err := iter .Next ()
917+ if err != nil {
918+ return err
919+ }
920+
921+ prettyPrintJSONObject (batch )
922+ pageItemsCount ++
923+ if pageItemsCount % pageSize == 0 && (! more || ! showNextPage ()) {
924+ break
925+ }
926+ }
927+
928+ return nil
929+ }
930+
904931// prompt will show input msg, then waiting user input y/yes to continue
905932func prompt (msg string , autoConfirm bool ) {
906933 reader := bufio .NewReader (os .Stdin )
You can’t perform that action at this time.
0 commit comments