Skip to content

Commit b477f25

Browse files
authored
Merge branch 'master' into feature/enum-zero
2 parents 97d9a55 + 1786350 commit b477f25

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

tools/cli/admin.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,44 @@ func newAdminShardManagementCommands() []cli.Command {
170170
AdminDescribeTask(c)
171171
},
172172
},
173-
173+
{
174+
Name: "list_tasks",
175+
Usage: "List tasks for given shard Id and task type",
176+
Flags: append(
177+
getDBFlags(),
178+
cli.StringFlag{
179+
Name: FlagTargetCluster,
180+
Value: "active",
181+
Usage: "Temporal cluster to use",
182+
},
183+
cli.IntFlag{
184+
Name: FlagShardID,
185+
Usage: "The ID of the shard",
186+
},
187+
cli.IntFlag{
188+
Name: FlagTaskType,
189+
Value: 2,
190+
Usage: "Task type: 2 - transfer task (default), 3 - timer task, 4 - replication task",
191+
},
192+
cli.StringFlag{
193+
Name: FlagMinVisibilityTimestamp,
194+
Value: "2020-01-01T00:00:00+00:00",
195+
Usage: "Task visibility min timestamp. Supported formats are '2006-01-02T15:04:05+07:00', raw UnixNano and " +
196+
"time range (N<duration>), where 0 < N < 1000000 and duration (full-notation/short-notation) can be second/s, " +
197+
"minute/m, hour/h, day/d, week/w, month/M or year/y. For example, '15minute' or '15m' implies last 15 minutes.",
198+
},
199+
cli.StringFlag{
200+
Name: FlagMaxVisibilityTimestamp,
201+
Value: "2035-01-01T00:00:00+00:00",
202+
Usage: "Task visibility max timestamp. Supported formats are '2006-01-02T15:04:05+07:00', raw UnixNano and " +
203+
"time range (N<duration>), where 0 < N < 1000000 and duration (full-notation/short-notation) can be second/s, " +
204+
"minute/m, hour/h, day/d, week/w, month/M or year/y. For example, '15minute' or '15m' implies last 15 minutes.",
205+
},
206+
),
207+
Action: func(c *cli.Context) {
208+
AdminListTasks(c)
209+
},
210+
},
174211
{
175212
Name: "close_shard",
176213
Aliases: []string{"clsh"},

tools/cli/adminCommands.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,48 @@ func AdminDescribeTask(c *cli.Context) {
408408
}
409409
}
410410

411+
// AdminListTasks outputs a list of a tasks for given Shard and Task Type
412+
func AdminListTasks(c *cli.Context) {
413+
sid := getRequiredIntOption(c, FlagShardID)
414+
category := commongenpb.TaskCategory(c.Int(FlagTaskType))
415+
416+
pFactory := CreatePersistenceFactory(c)
417+
executionManager, err := pFactory.NewExecutionManager(sid)
418+
if err != nil {
419+
ErrorAndExit("Failed to initialize execution manager", err)
420+
}
421+
422+
if category == commongenpb.TaskCategory_TaskCategory_Transfer {
423+
req := &persistence.GetTransferTasksRequest{}
424+
tasks, err := executionManager.GetTransferTasks(req)
425+
if err != nil {
426+
ErrorAndExit("Failed to get Transfer Tasks", err)
427+
}
428+
prettyPrintJSONObject(tasks)
429+
} else if category == commongenpb.TaskCategory_TaskCategory_Timer {
430+
minVisFlag := parseTime(c.String(FlagMinVisibilityTimestamp), 0, time.Now())
431+
minVis := time.Unix(0, minVisFlag)
432+
maxVisFlag := parseTime(c.String(FlagMaxVisibilityTimestamp), 0, time.Now())
433+
maxVis := time.Unix(0, maxVisFlag)
434+
435+
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)
439+
}
440+
prettyPrintJSONObject(tasks)
441+
} else if category == commongenpb.TaskCategory_TaskCategory_Replication {
442+
req := &persistence.GetReplicationTasksRequest{}
443+
task, err := executionManager.GetReplicationTasks(req)
444+
if err != nil {
445+
ErrorAndExit("Failed to get Replication Tasks", err)
446+
}
447+
prettyPrintJSONObject(task)
448+
} else {
449+
ErrorAndExit("Failed to describe task", fmt.Errorf("Unrecognized task type, task_type=%v", category))
450+
}
451+
}
452+
411453
// AdminRemoveTask describes history host
412454
func AdminRemoveTask(c *cli.Context) {
413455
adminClient := cFactory.AdminClient(c)

tools/cli/flags.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ const (
197197
FlagTaskID = "task_id"
198198
FlagTaskType = "task_type"
199199
FlagTaskVisibilityTimestamp = "task_timestamp"
200+
FlagMinVisibilityTimestamp = "min_visibility_ts"
201+
FlagMaxVisibilityTimestamp = "max_visibility_ts"
200202
FlagStartingRPS = "starting_rps"
201203
FlagRPS = "rps"
202204
FlagRPSScaleUpSeconds = "rps_scale_up_seconds"

0 commit comments

Comments
 (0)