Skip to content

Commit ca98885

Browse files
authored
Add GetActivityTaskList and GetWorkflowTaskList utils to replace WithTaskListMapper utils (#1292)
What changed? Remove WithTasklist utils introduced in #1286 Instead, users should use the new GetTaskList and With*TaskList APIs. For future as discussed with @Groxx, it's better to have a functional API to replace all "With*". For example: ExecuteChildWorkflow(ctx, type, child.Args(all, args), child.WorkflowID("asdf')) Why? With**TaskList APIs are confusing and it's better to remove it
1 parent e537cbf commit ca98885

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

internal/workflow.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,16 +1413,14 @@ func WithWorkflowTaskList(ctx Context, name string) Context {
14131413
return ctx1
14141414
}
14151415

1416-
// WithWorkflowTaskListMapper returns a copy of context and changes workflow tasklist with mapper function.
1417-
func WithWorkflowTaskListMapper(ctx Context, mapper func(string) string) Context {
1418-
ctx1 := setWorkflowEnvOptionsIfNotExist(ctx)
1419-
var taskList string
1420-
if getWorkflowEnvOptions(ctx1).taskListName != nil {
1421-
taskList = *getWorkflowEnvOptions(ctx1).taskListName
1416+
// GetWorkflowTaskList retrieves current workflow tasklist from context
1417+
func GetWorkflowTaskList(ctx Context) *string {
1418+
wo := getWorkflowEnvOptions(ctx)
1419+
if wo == nil || wo.taskListName == nil {
1420+
return nil
14221421
}
1423-
newTaskList := mapper(taskList)
1424-
getWorkflowEnvOptions(ctx1).taskListName = &newTaskList
1425-
return ctx1
1422+
tl := *wo.taskListName // copy
1423+
return &tl
14261424
}
14271425

14281426
// WithWorkflowID adds a workflowID to the context.
@@ -1813,12 +1811,14 @@ func WithTaskList(ctx Context, name string) Context {
18131811
return ctx1
18141812
}
18151813

1816-
// WithTaskListMapper makes a copy of the context and apply the tasklist mapper function
1817-
// Note this shall not confuse with WithWorkflowTaskListMapper. This is the tasklist for activities.
1818-
func WithTaskListMapper(ctx Context, mapper func(string) string) Context {
1819-
ctx1 := setActivityParametersIfNotExist(ctx)
1820-
getActivityOptions(ctx1).TaskListName = mapper(getActivityOptions(ctx1).TaskListName)
1821-
return ctx1
1814+
// GetActivityTaskList retrieves tasklist info from context
1815+
func GetActivityTaskList(ctx Context) *string {
1816+
ao := getActivityOptions(ctx)
1817+
if ao == nil {
1818+
return nil
1819+
}
1820+
tl := ao.TaskListName // copy
1821+
return &tl
18221822
}
18231823

18241824
// WithScheduleToCloseTimeout adds a timeout to the copy of the context.

workflow/activity_options.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,14 @@ func WithTaskList(ctx Context, name string) Context {
5858
return internal.WithTaskList(ctx, name)
5959
}
6060

61-
// WithTaskListMapper makes a copy of current context and update the tasklist with mapper function.
62-
// Note this is the tasklist for activity tasklist. For workflow tasklist, use WithWorkflowTaskListMapper
63-
func WithTaskListMapper(ctx Context, mapper func(string) string) Context {
64-
return internal.WithTaskListMapper(ctx, mapper)
61+
// GetActivityTaskList returns tasklist in the Context's current ActivityOptions,
62+
// or workflow.GetInfo(ctx).TaskListName if not set or empty
63+
func GetActivityTaskList(ctx Context) string {
64+
tl := internal.GetActivityTaskList(ctx)
65+
if tl != nil && *tl != "" {
66+
return *tl
67+
}
68+
return GetInfo(ctx).TaskListName
6569
}
6670

6771
// WithScheduleToCloseTimeout makes a copy of the current context and update

workflow/workflow_options.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ func WithWorkflowTaskList(ctx Context, name string) Context {
4242
return internal.WithWorkflowTaskList(ctx, name)
4343
}
4444

45-
// WithWorkflowTaskListMapper returns a copy of Context with changed tasklist
46-
func WithWorkflowTaskListMapper(ctx Context, mapper func(name string) string) Context {
47-
return internal.WithWorkflowTaskListMapper(ctx, mapper)
45+
// GetWorkflowTaskList returns tasklist in the Context's current ChildWorkflowOptions
46+
// or workflow.GetInfo(ctx).TaskListName if not set or empty.
47+
func GetWorkflowTaskList(ctx Context) string {
48+
tl := internal.GetWorkflowTaskList(ctx)
49+
if tl != nil && *tl != "" {
50+
return *tl
51+
}
52+
return GetInfo(ctx).TaskListName
4853
}
4954

5055
// WithWorkflowID adds a workflowID to the context.

0 commit comments

Comments
 (0)